by mdwheaton at 2013-04-22 11:45:43
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.by poshoholic at 2013-04-23 21:15:28
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.
$ZipFile = $args
Write-Host “2 - $ZipFile”
$TargetDir = $args
Write-Host “3 - $TargetDir”
new-item $TargetDir -itemtype directory -ErrorAction SilentlyContinue
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($ZipFile)
$destination = $shell_app.namespace($TargetDir)
Start-Sleep -s 10
Write-Host “Generic Exception”
$ | Select *
The output I get is :
2 - c:\somedir\somezip.zip
3 - c:\somedir
Here’s one suggestion for finding hard-to-find errors like this: at the top of your script, invoke the following:
Then, later in your script, after you think the zip extraction is complete, check if $Error contains anything and try to write it to disk so that you can see what non-terminating errors occurred when you run it as a shutdown script.