I'm trying to execute a PowerShell script from an alert action.
I have made the appropriate changes to the service so it is not running under a local system account, per discussions I found here.
The command that I have entered into the Execute external program:
apm\powershell.exe -file "c:\ps\CPU_Usage.ps1" ${NodeName}
PowerShell Script:
$Node=$args[0]
$timestamp = Get-date -Format yyyymmdd-hhmmss
$File = "C:\PS\Logs\CPU_" + $Node + "_" + $timestamp + ".txt"
out-file $file
Get-WmiObject -ComputerName $Node Win32_PerfFormattedData_PerfProc_Process | Select-Object pscomputername, Name, PercentProcessorTime | FT -AutoSize | Out-File $file -Append
The problem I'm running into and can't seem to get past is the execution of the last line. This script will run and create the file in the directory, but it will never get updated with the data from the Get-WmiObject command.
If I log into my server with the same account that I'm running the Alerting Engine as and manually run the PowerShell script it returns the data just fine.
Anyone have any suggestions?