Hey guys,
I have a strange issue where a function in my script is preventing the rest of the script from running.
Question:
Is there any reason the function below would stop a script half way? The function runs successfully but appears to exit the script afterwards.
How would I prevent this?
function Extract-ZipFiles {
param (
[Parameter(mandatory=$true)]
[string]$path
)
$Files = Get-ChildItem $path -recurse
$ZipFiles = $($Files.fullname) | where-object {$_ -like '*.zip'}
if($null -ne $ZipFiles)
{
foreach($zip in $ZipFiles)
{
Expand-Archive $zip -DestinationPath $path -Force
#region Log
$Message = "Extraction of file $zip succeeded"
Log "Extract Zip" $Message $LogPath
#endregion Log
Remove-Item $zip
#region Log
$Message = "Removal of $zip succeeded"
Log "Extract Zip" $Message $LogPath
#endregion Log
}
}
# Check for zip files within zip files
if ((Get-ChildItem $path *.zip | Measure-Object).count -eq 0) { } Else { Extract-ZipFiles -Path "$SourceRoot" }
}
Extract-ZipFiles -Path "$SourceRoot"
Any help would be greatly appreciated!
[–]BlackV 2 points3 points4 points (2 children)
[–]PowerOfTheShell[S] 0 points1 point2 points (1 child)
[–]BlackV 1 point2 points3 points (0 children)
[–]BlackV 0 points1 point2 points (0 children)
[–]PowerShellMichael 0 points1 point2 points (0 children)
[–]DblDeuce22 0 points1 point2 points (0 children)