PowerShell管理SCOM2007R2

get-operationsmanagercommandshell

#定義RMS服務器名稱(SCOM管理控制檯所在服務器名稱)
#Connect to the RMS server and initialize the command shell
$rmsServerName=」scomw.testj.com」
#向當前會話添加scom管理單元
add-pssnapin 「Microsoft.EnterpriseManagement.OperationsManager.Client」
#將當前工做會話設置爲SCOM
Set-Location 「OperationsManagerMonitoring::」
#測試管理組鏈接是否正常,管理組能夠更改
$mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName
if($mgConn -eq $null)
{
[String]::Format(「Failed to connect to RMS on ‘{0}’」,$rmsServerName)
return;
}
#設置當前工做會話到scom管理控制檯服務器
Set-Location $rmsServerNameapi

#######經過路徑導航到每臺計算機下對其進行設置維護模式#############################
#獲取監視對象
get-monitoringobject
#導航到所須要的路徑下
cd Microsoft.SystemCenter.AllComputersGroup\win08r2.testj.com
#對當前路徑新建維護模式
$time = [DateTime]::Now
New-MaintenanceWindow -starttime: ($time) -endTime: ($time.AddDays(1)) -reas
on: "ApplicationInstallation" -comment: "Testing DateTime.Now"
##################################################################################
##################################################################################服務器

##################能夠單獨對每臺計算機設置維護模式#################
#定義須要設置維護模式的計算機名稱
$servername_maintenance = "win08r2.testj.com"
$time = [DateTime]::Now
#經過agent獲取Monitoringobject
$agent = get-agent|where {$_.name -eq $servername_maintenance}
$server = $agent.hostcomputeride

#也能夠對組直接設置
#$MonitoringClassCG = get-monitoringclass | where {$_.DisplayName -eq $groupName}
#$MonitoringGUID = get-monitoringobject $MonitoringClassCG.Id測試


#設置具體結束時間
New-MaintenanceWindow -Monitoringobject $server -Comment "maintenance test" -Starttime $time -Endtime "3/2/2013 12:00"
#設置維護模式時長
New-MaintenanceWindow -Monitoringobject $server -Comment "maintenance test" -Starttime $time -Endtime $time.addminutes(30)orm

#獲取計算機的維護模式狀態,兩種方法都可
get-maintenancewindow -monitoringobject $server |get-member
$? #若是未處於維護模式,則會報錯
#$server|get-maintenancewindowserver


#結束維護模式
$time1=get-date
取消維護模式,兩種方法都可
Set-MaintenanceWindow -Monitoringobject $server -Endtime $time1
#$server|Set-MaintenanceWindow -Endtime $time1對象

相關文章
相關標籤/搜索