A nice feature with alarms and the "Run a script" action is that you can pass parameters to the script.
See the VIC help under "Setting and Viewing Alarms : Creating and Editing Alarms : Alarm Settings – Actions".
The way I do this is as follows:
1) Specify the parameters you want to pass in the Action field
c:\windows\system32\cmd.exe /c c:\Scripts\alarmscript2.bat {targetName} {alarmName}
2) Pass the parameters in the BAT file to the PS script
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsolefile "C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\vim.psc1" -Command C:\Scripts\Test-Alarm.ps1 %1 %2
3) Define the parameters in the PS script
Param (
[string] $targetName,
[string] $alarmName
)
$targetName | Out-File "C:\Scripts\PSOut.log" -Append
$alarmName | Out-File "C:\Scripts\PSOut.log" -Append
Watch out with global alarms.
Each entity for which the alarm is triggered will start a PS shell to execute the script.
That can give quit some overhead on the VC server.