Hi Guys,
I am currently trying to write a powershell script that at some point will extract a zip file into a folder and then the zip files within that folder.
So far my code goes like this.
##GETZIP() - Retreive the zip folder and extract it to an output location## function getZip() { #Change the Path variable $location= Read-host 'Enter your zip folder path' $oDestination = $path + \Output extractZip $location $oDestination } function extractZip($path, $destination) { #Force the location into existence New-Item -ItemType Directory -Force -Path $destination$shell_app= New-Object -com shell.application #Get .zip from path location$files = Get-ChildItem -Path $path -filter *.zip -recurse #for each file within the zip extract to the output folder foreach($file in $files) { $zip_file = $shell_app.namespace($file.FullName) $copyHere = $shell_app.namespace($destination) $copyHere.Copyhere($zip_file.items()) } }
Now when I run this code I get a "You cannot call a method on a null-valued expression...$copyHere.CopyHere <<<< ($zip_files())" is causing the issue. Yet if I revert to some older code this works without issue.
##GETZIP() - Retreive the zip folder and extract it to an ouput location## function getZip() { # Change the Path variable $path = Read-host 'Enter your zip folder path' $destination = $path + \Output #Force the location into existence New-Item -ItemType Directory -Force -Path $destination $shell_app= New-Object -com shell.application #Get .zip from path location $files = Get-ChildItem -Path $path -filter *.zip -recurse #for each file within the zip extract to the output folder foreach($file in $files) { $zip_file = $shell_app.namespace($file.FullName) $copyHere = $shell_app.namespace($destination) $copyHere.Copyhere($zip_file.items()) } }
What gives?