Hello,
i need to unzip a file and copy to different location…
sometimes its working under the local files but when i give shared location it doesnt…
please help me on this
param
(
[string]$spath,
[string]$destination
)
$files = Get-ChildItem $spath -include test*.zip -Recurse
foreach ($file in $files)
{
$archiveFile = $spath + $file.Name | out-string -stream
"Extracting the zip file to below location: " + $archiveFile
"Destination location : " + $destination
#$ErrorActionPreference = "SilentlyContinue"
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($archiveFile)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
}
it throws the following error
You cannot call a method on a null-valued expression.
At L:\unzip.ps1:24 char:50
-
$destinationFolder.CopyHere($zipPackage.Items <<<< ())
- CategoryInfo : InvalidOperation: (Items:String) , RuntimeException
- FullyQualifiedErrorId : InvokeMethodOnNull
Thanks in advance