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

  • 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 7: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 7: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 7: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 3: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.