Powershell script to unzip file from Task Scheduler doesnt work using the SYSTEM account
 I run multiple powershell scripts from task scheduler using the SYSTEM account.  This is the only script that does not work.  This script needs a Windows user account defined in task scheduler to run.  Is there a way to get this script to work using the SYSTEM account?  If not, is there another way to unzip files using powershell that does not have this requirement?  Below is the code:

function Expand-ZIPFile
{
param($file, $destination)
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item,1564)
"$($item.path) extracted"
}
}

$hc_zip = $args[0]
$hc_zip

$hc_dest = $args[1]

if (Test-Path $hc_zip){Expand-ZIPFile File $hc_zip Destination "$hc_dest}
else{Write-Output "Zip file does not exist...;"}

September 11th, 2015 9:33am

What is the error you are receiving?
Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 9:51am

Don't use the shell, it's not meant for use like that.

Look at using .Net 4.5's ZipFile class instead. There are many threads here that have code for this.

Alternatively you can look at PSCX.

September 11th, 2015 9:56am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics