I'm trying to unzip a bunch of archives including the new xlsx files into a TMP folder and then work on that folder and then remove it. And shit just doesnt want to go my way.
$spath = "C:\_PS\TestFolder"
$destination=”C:\TestFolder\Testzip"
Get-ChildItem $spath -include *.xlsx -Recurse | foreach-object {
# Remove existing TMP folder and create a new one
Remove-Item -Recurse -Force $destination
New-Item $destination -type directory
$archiveFile = $_.fullname | out-string -stream
"Extract this: " + $archiveFile
"To here: " + $destination
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($archiveFile)
$destinationFolder = $shellApplication.NameSpace($destination)
$destinationFolder.CopyHere($zipPackage.Items())
}
And it always gives me these errors
Exception calling "NameSpace" with "1" argument(s): "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))" At C:\_PS\FindCC.ps1:62 char:46
+ $zipPackage = $shellApplication.NameSpace <<<< ($archiveFile)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation You cannot call a method on a null-valued expression. At C:\_PS\FindCC.ps1:64 char:50
+ $destinationFolder.CopyHere($zipPackage.Items <<<< ())
+ CategoryInfo : InvalidOperation: (Items:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull