I have the following .ps1 for unzipping a zip file...
param([string]$path)
$shell=new-object -com shell.application
$Location=$shell.namespace($path)
$ZipFiles = get-childitem *.zip
get-childitem $path -include *.xml -recurse | foreach ($_) {remove-item $_.fullname}
foreach ($ZipFile in $ZipFiles)
{
$ZipFile.fullname | out-default
$ZipFolder = $shell.namespace($ZipFile.fullname)
$Location.Copyhere($ZipFolder.items())
}
and the following run.bat file for setting the parameter and calling the .ps1
powershell -command "C:\Users\eric\unzipFile\unzip3.ps1 -path \"C:\Users\eric\unzipFile\""
If both are in the same directory, no error, however if I move the run.bat to another directory I get the following...
You cannot call a method on a null-valued expression.
At C:\Users\eric\unzipFile\unzip3.ps1:12 char:38
+ $Location.Copyhere($ZipFolder.items <<<< ())
+ CategoryInfo: InvalidOperation: (items:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
$ZipFiles = get-childitem *.zip
. AddWrite-Host $pwd
before that to see where it's looking for *.zip. – Andy Arismendi May 21 at 20:34