$results=@()
foreach ($m in $ms) { $result=""|select a,b,c $result.a = $m.a $result.b = $m.b $result.c = $m.c $results += $result }$results | export-csv -encoding utf8 -notypeinformation -path c:\perc\result.csv
####################################################################
$performance_monitor_result = "C:\scom_collect\performance_monitor.csv"
#定义RMS服务器名称$rmsServerName="CSserver.testj.com"#向当前会话添加scom管理单元add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"#$error|out-file c:\scomm\error.txt#将当前工作会话设置为SCOMSet-Location "OperationsManagerMonitoring::"#测试管理组连接是否正常,管理组可以更改$mgConn = New-ManagementGroupConnection -connectionString:$rmsServerNameif($mgConn -eq $null){ [String]::Format("Failed to connect to RMS on '{0}'",$rmsServerName) return;}#设置当前工作会话到scom管理控制台服务器Set-Location $rmsServerName$start = get-date
#获取计数器名称
function GetCountername ([String] $configuration) { $config = [xml] ("<config>" + $configuration + "</config>") $countername = $config.config.countername return $countername }#获取监控频率
function Getfrequency ([String] $configuration) { $config = [xml] ("<config>" + $configuration + "</config>") $frequency = $config.config.frequency if ($frequency -eq $null) {$frequency = "intervalseconds is:" + $config.config.IntervalSeconds} return $frequency } #获取阀值function Getthreshold ([String] $configuration) { $config = [xml] ("<config>" + $configuration + "</config>") $threshold = $config.Config.Threshold if($threshold -eq $null) { $threshold = $config.Config.MemoryThreshold } if($threshold -eq $null) { $threshold = $config.Config.CPUPercentageThreshold } if($threshold -eq $null) { if($config.Config.Threshold1 -ne $null -and $config.Config.Threshold2 -ne $null) { $threshold = "first threshold is:" + $config.Config.Threshold1 + " second threshold is:" + $config.Config.Threshold2 } } if($threshold -eq $null) { if($config.Config.ThresholdWarnSec -ne $null -and $config.Config.ThresholdErrorSec -ne $null) { $threshold = "warning threshold is:" + $config.Config.ThresholdWarnSec + " error threshold is:" + $config.Config.ThresholdErrorSec } } if($threshold -eq $null) { if($config.Config.LearningAndBaseliningSettings -ne $null) { $threshold = "no threshold (baseline monitor)" } } return $frequency,$threshold }#获取采样数
function GetNumSamples ([String] $configuration) { $config = [xml] ("<config>" + $configuration + "</config>") $NumSamples = $config.config.NumSamples return $NumSamples }$perhealths = get-monitor|?{$_.Category -eq "PerformanceHealth"}
$perhealths |select-object @{name = "monitor_name";expression = {$_.displayname}},` @{name = "monitor_name_real";expression = {$_.name}},` @{name = "monitor_server";expression = {foreach-object {(get-monitoringclass -id:$_.target.id).displayname}}},` @{name = "countername";expression = {foreach-object {GetCountername $_.configuration}}},` @{name = "threshold";expression = {foreach-object {Getthreshold $_.configuration}}},` @{name = "numbersamples";expression = {foreach-object {GetNumSamples $_.configuration}}},` @{name = "frequency";expression = {foreach-object {Getfrequency $_.configuration}}},` @{name = "configuration";expression = {$_.configuration}}` |sort monitor_name |export-csv -encoding UTF8 -path C:\scom_collect\performance_monitor.csv