1

I have a power-shell-script which is called by a batch-file. The batch calls the script after it has set the execution policy to unrestricted. Currently the script does nothing more than writing a log-file, logging that it has been executed.

Now the odd thing:

Scenario 1: I'm logged in, double click the batch-file, the script is immediately executed, log file is written correctly. Everything works as expected.

Scenario 2: I'm not logged in, the batch-file is executed correctly by our UPS, an APC Smart-UPS RT 3000XL with a PCNS-card (I can see the execution time of the batch in a different log), but the power-shell-script is not always executed immediately. Instead I have to wait either exactly 5 or exactly 10 minutes

I doubt that this is a security-issue because sooner or later the script is executed.

Here's the batch:

echo Shutdown Script > c:\PowerChuteNWShutdown\Start.txt C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command get-executionpolicy C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command set-executionpolicy Unrestricted C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -psc "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -noe -c "& 'C:\PowerChuteNWShutdown\lab_shutdown.ps1'" -Verb RunAs

and the script:

$Logfile = "C:\PowerChuteNWSHUTDOWN\Log.txt"
Write-Output "Begin lab_shutdown"
Out-File $Logfile
Get-Date | Out-File $Logfile -append

Has anyone a explanation for this behavior? Thank you in advance

beatcracker
  • 1,359
  • 8
  • 13
  • Our UPS is not able to call a Powershell-script. I already spent hours to try this, the UPS will only call a single-line batch-file. – Christof Walker Nov 20 '14 at 07:02
  • Ah. You should include that in the question, along with the make and model of the UPS. As well as clarification as to what, exactly, you're logged into. Off the top of my head, it sounds like your exactly 5 or 10 minute delay is probably caused by the UPS scheduling activity, on account of its limited processing power/resources. – HopelessN00b Nov 20 '14 at 07:08
  • OK, added the UPS-Model in my question. As for the credentials. When I'm logged in I have local Administration rights on the computer which hosts the script. The service of the UPS has also local Admin rights and may run batch files. The batch file is called right on time by the UPS (I can see the timestamp of the log which is written by the batch) after it received the event-trigger. – Christof Walker Nov 20 '14 at 07:41
  • So the UPS is running the batch file (and writing to Start.txt), but ps.ps1 is not executing for either 5 or 10 minutes? – xXhRQ8sD2L7Z Nov 21 '14 at 03:11
  • Does this 5 to 10 min delay happen when you remove PowerCLI from the scenario?. Remove the '-PSConsole' (-psc) option and the *.psc1 file and see if the delay is there... – Signal15 Nov 21 '14 at 14:05
  • @ST8Z6FR57ABE6A8RE9UF: Yes, that's correct – Christof Walker Nov 21 '14 at 14:58
  • @Signal15: I tried your suggestion, removing the -psc option. The result is the same. Batch is run immediately, script is run after 5 minutes. – Christof Walker Nov 21 '14 at 15:01
  • `...\vim.psc1" -noe -c "& 'C:\PowerChuteNWShutdown\lab_shutdown.ps1'" ...` in your batch last line should be `...\vim.psc1" -noe -c ^& "C:\PowerChuteNWShutdown\lab_shutdown.ps1" ...`. Note `&` ampersand escaped (used `^&` outside double quotes) such that `cmd` will treat it literally and will supply it into PowerShell unescaped and note removed single quotes. – JosefZ Jun 10 '15 at 21:52

0 Answers0