I have a script to unzip files that I'm testing as a shutdown script. I have the property to visibly display script output set to true as well so I can see if it's being run. The script doesn't execute properly when it's used as a shutdown script.
The script runs as expected from the command line. Also runs correctly when testing the script using psexec to run as SYSTEM.
Here's the script. The output follows the script. All the output lines display properly. The script also sleeps at the end as expected. However, the zip file does NOT get extracted. The script goes right through that line and doesn't even throw an exception. Again, this script runs perfectly from the command line.
I'm stumped as to why all the rest of the script works, but the unzip part doesn't.
Write-Host "Hello" try { Write-Host "1" $ZipFile = $args[0] Write-Host "2 - $ZipFile" $TargetDir = $args[1] Write-Host "3 - $TargetDir" new-item $TargetDir -itemtype directory -ErrorAction SilentlyContinue Write-Host "4" $shell_app=new-object -com shell.application Write-Host "5" $zip_file = $shell_app.namespace($ZipFile) Write-Host "6" $destination = $shell_app.namespace($TargetDir) Write-Host "7" $destination.Copyhere($zip_file.items()) Write-Host "8" Start-Sleep -s 10 exit 0 } Catch [Exception] { Write-Host "Generic Exception" Write-Host $_ $_ | Select * exit 1 }
The output I get is :
Hello 1 2 - c:\somedir\somezip.zip 3 - c:\somedir 4 5 6 7 8