SCOM MP中的PowerShell脚本

该脚本可在MP中运行

#param ($file,$threshold)  #此处可定义file 和 threshold 参数,该参数可以从脚本外部接收
$threshold = 10
$file = "C:inetpubmpps_test3.txt"
$sys = gwmi win32_computersystem
[int]$mem = $sys.TotalPhysicalMemory/1024/1024/1024

$api = New-Object -ComObject "MOM.ScriptAPI"
$bag = $api.CreatePropertyBag()

if ($mem -ge $threshold)
{
$bag.AddValue("State","OK")
$bag.AddValue("Description",$mem)
(get-date -uformat "%Y%m%d%H%M") + " okk " + $mem |out-file $file -append
}
else
{
$bag.AddValue("State","Error")
$bag.AddValue("Description",$mem)
(get-date -uformat "%Y%m%d%H%M") + " Errorr " + $mem |out-file $file -append
}
$bag
原文地址:https://www.cnblogs.com/dreamer-fish/p/3951447.html