astrolab
Contributor
Contributor

Calling a Powershell script from Aarm

I have been reading up on how to get a script to run when a specific alarm is triggered.

To that order, I created a .BAT file on the VC server, calling a PS1 script. When I run the batch file from CMD on the VC server, everything works just fine and the script completes successfully. When the alarm rings though the script does not run, in the configuration field I entered :

C:\windows\system32\cmd.exe /c c:\scripts\myscript.bat

Again, the script works fine when launched from command prompt on the VC server, so it does have to do with VC. I have tried with the Execution Policy set to both Unresricted and remotesigned, to no avail. Any help will be appreciated, thank you.

0 Kudos
5 Replies
LucD
Leadership
Leadership

Did you already check out Carter's blog post How to run PowerCLI scripts from vCenter Alarms ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Zsoldier
Expert
Expert

Nevermind, Luc got your answer.

Chris Nakagaki (Zsoldier)

Message was edited by: Zsoldier

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
astrolab
Contributor
Contributor

I have, thank you. The script runs from CMD on the VC server, the interaction with VC though does not work. I though the way I am running the script will interact with VC under the VPXD account.

0 Kudos
RvdNieuwendijk
Leadership
Leadership

Do you use the Connect-VIServer cmdlet in your script to connect to the vCenter server? This cmdlet will establish the connection with the vCenter server. E.g.:

$vCenterServer = Connect-VIServer -Server YourvCenterServer.YourDomain.YourCountry -User Username -Password Password

Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
astrolab
Contributor
Contributor

Yes, thank you. I had to resort to put the username and the password in the script to make it work.

0 Kudos