Use powershell to unzip files without specifiying zip file name

So One year passed by, my son turns one year old the 11th of February so it’s back to work for me! And what better way to start then to start a fight with Powershell. I gotta tell you, scripting with Powershell is like playing MUD (command-line based role playing). Very addictive and time just passes in a flash!

I was searching for a script to unzip a file but I only found scripts where you had to specify a static path to the filename OR the script was seven pages long OR you needed to run it with parameters… So after some hacking and constructing it came down to this:

# Change the Path & Destination variable

$path = “C:\Whereisthezip”

$destination = “C:\Wheredoyouwanttounzip”

 $shell_app= New-Object -com shell.application

$files = Get-ChildItem -Path $path -filter *.zip -recurse

foreach($file in $files) {

  $zip_file = $shell_app.namespace($file.FullName)

  $copyHere = $shell_app.namespace($destination)

  $copyHere.Copyhere($zip_file.items())

}

Thanks to Niklas Goude I didn’t have to spend one more day with it 😉