# Assign script name variable for use in event logging
$ScriptName = "Approved.System.Center.Operations.Manager.2016.Performance.Monitoring.MeasureGetSCOMEvent.PowerShell.Script.Perf.PA.ps1"
#=================================================================================
# Gather script start time
$StartTime = Get-Date
# Gather who the script is running as
$whoami = whoami
# Load MOMScript API and Propertybag for output
$momapi = New-Object -comObject MOM.ScriptAPI
# Log an event for the script starting
$momapi.LogScriptEvent($ScriptName,1234,0, "Script is starting. Running, as ($whoami).")
# Main body of the script
#=================================================================================
# Any Arguments specified will be sent to the script as a single string.
# If you need to send multiple values, delimit them with a space, semicolon or other separator and then use split. param([string]$Arguments)
# Collect your performance counter here. Note that in order to support the DW this script MUST only return a single
# object/counter and those must be static values. You can return multiple instances just fine though.
#Log an event for script ending and total execution time.
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
$momapi.LogScriptEvent($ScriptName,1235,0,"Script has completed. Runtime was ($ScriptTime) seconds. Output value: ($Metric)")