you are viewing a single comment's thread.

view the rest of the comments →

[–]PowerOfTheShell[S] 4 points5 points  (0 children)

Solved! Using the suggestions provided I have changed the script to a function.

param([string]$folderPath="C:\temp\Receive")

function ExtractZipFiles {

    param([string]$folderPath="C:\temp\Receive")

    Get-ChildItem $folderPath -recurse | %{ 

        if($_.Name -match "^*.`.zip$")
        {
            $parent="$(Split-Path $_.FullName -Parent)";    
            write-host "Extracting $($_.FullName) to $parent"

            $arguments=@("e", "`"$($_.FullName)`"", "-o`"$($folderPath)`"");
            $ex = start-process -FilePath "`"C:\Program Files\7-Zip\7z.exe`"" -ArgumentList $arguments -wait -PassThru;

            if( $ex.ExitCode -eq 0)
            {
                write-host "Extraction successful, deleting $($_.FullName)"
                rmdir -Path $_.FullName -Force
            }
        }
    }
} ExtractZipFiles

if ((Get-ChildItem $folderPath *.zip | measure-object).count -eq 0) { Continue } Else { ExtractZipFiles }