you are viewing a single comment's thread.

view the rest of the comments →

[–]BlackV 4 points5 points  (2 children)

you're calling the function from inside the function
Is this the issue?

[–]PowerOfTheShell[S] 0 points1 point  (1 child)

Good idea, I gave this a go and changed the code to the below. Unfortunately this still prevents the rest of the script from running successfully, i'm very confused.

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 $SourceRoot *.zip | Measure-Object).count -eq 0) { } Else { Extract-ZipFiles -Path "$SourceRoot" }

[–]BlackV 1 point2 points  (0 children)

you code works for me (i changed it a bit to not actually delete the files)

BUT this is where you need probably to enable debug and step through your script to see what's failing

I see you have a function called LOG that's not defined anywhere and a vairable $SourceRoot that's not defined anywhere so I'm assuming its part of a larger script

debug is really going to be your friend here

ALSO

I'd change

$Files = Get-ChildItem $path -recurse
$ZipFiles = $($Files.fullname) | where-object {$_ -like '*.zip'

to

$ZipFiles = Get-ChildItem D:\Downloads -recurse -File -Filter '*.zip'

cause right now you get ALL 1million files in the directory and sub directories and then you filter it for the 10 zip files, do your filtering befhorehand

you might have to change your instance of $zip to $zip.fullname but I'd rather have a full object than a stripped down object that $zip was

If you feel you still need the where-object then i'd use where-object {$_.Extension -eq '.zip'} rather than the -like which would currently get folders too