#script
#unzip folder
$shell_app = new-object -com shell.application
$filename = "temp.zip"
$zip_file = $shell_app.namespace("C:\temp\$filename")
#set the destination directory for the extracts
if (Test-Path "C:\temp\zipfiles\") { $destination = $shell_app.namespace("C:\temp\zipfiles") }
else { mkdir C:\temp\zipfiles ; $destination = $shell_app.namespace("C:\temp\zipfiles")}
#unzip the file
$destination.Copyhere($zip_file.items(),2048)
gives error :
Method invocation failed because [System.String] doesn't contain a method named 'items'.
At line:11 char:45
+ [string] $Location.Copyhere($ZipFolder.items <<<< (),2048)
+ CategoryInfo : InvalidOperation: (items:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
one more script like above gives another error below :
$shell=new-object-com shell.application $CurrentLocation="c:\temp" $CurrentPath=$CurrentLocation.path $Location=$shell.namespace($CurrentPath) $ZipFiles =get-childitem *.zip $ZipFiles.count |out-defaultforeach($ZipFile in $ZipFiles){ $ZipFile.fullname |out-default $ZipFolder = $shell.namespace($ZipFile.fullname) $Location.Copyhere($ZipFolder.items())}
I am trying to unzip files on same location getting error:
You cannot call a method on a null-valued expression.
At line:10char:36
+ $Location.Copyhere($ZipFolder.items <<<<())
+CategoryInfo :InvalidOperation:(items:String)[],RuntimeException
+FullyQualifiedErrorId:InvokeMethodOnNull