I got a following script from the internet, when I tried to run it gives me an error.
#script
#unzip folder
$shell_app = new-object -com shell.application
$filename = "test.zip"
$zip_file = $shell_app.namespace("C:\temp\$filename")
#set the destination directory for the extracts
$destination = $shell_app.namespace("C:\temp\zipfiles")
#unzip the file
$destination.Copyhere($zip_file.items())
--- Error Message
You cannot call a method on a null-valued expression.
At line:1 char:22
+ $destination.Copyhere <<<< ($zip_file.items())
+ CategoryInfo : InvalidOperation: (Copyhere:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
you need to create the "c:\temp\zipfiles" folder before you set the $destination variable, this kind of sloppy way but it will do the job :)
#script
#unzip folder
$shell_app = new-object -com shell.application
$filename = "test.zip"
$zip_file = $shell_app.namespace("C:\temp\$filename")
#set the destination directory for the extracts
if (!(Test-Path "C:\temp\zipfiles\")) {
mkdir C:\temp\zipfiles
}
$destination = $shell_app.namespace("C:\temp\zipfiles")
#unzip the file
$destination.Copyhere($zip_file.items())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With