Error Calling powershell script from batch file in separate directory -
i have following .ps1 unzipping 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 following run.bat file setting parameter , calling .ps1
powershell -command "c:\users\eric\unzipfile\unzip3.ps1 -path \"c:\users\eric\unzipfile\""
if both in same directory, no error, if move run.bat directory following...
you cannot call method on null-valued expression. @ c:\users\eric\unzipfile\unzip3.ps1:12 char:38 + $location.copyhere($zipfolder.items <<<< ()) + categoryinfo: invalidoperation: (items:string) [], runtimeexception + fullyqualifiederrorid : invokemethodonnull
you didn't specify in path zip files, looks in current folder. change follow:
$zipfiles = get-childitem -path $path -filter *.zip
other tip: use -file parameter powershell , add other parameters make easier call
powershell -file "c:\users\eric\unzipfile\unzip3.ps1" -path "c:\users\eric\unzipfile\"
Comments
Post a Comment