Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

unzip from zip file is not taken place gives error

$
0
0

#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


Viewing all articles
Browse latest Browse all 8583

Trending Articles