2016年3月22日 星期二

Place a Group in Maintenance Mode with Powershell

Sample Commandline: GroupatonceMM.ps1 GROUPNAME MMDURATIONINHOURS RMSSERVERNAME

Script name:  GroupatonceMM.ps1 param ($groupName, $MMDuration, $rmsServerName)
#Load the Operations Manager snapin and connect to the Root Management Server
add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
Set-Location "OperationsManagerMonitoring::";
$mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName;
if($mgConn -eq $null)
{
[String]::Format("Failed to connect to RMS on ‘{0}’",$rmsServerName);
return;
}

Set-Location $rmsServerName;
$startTime = [DateTime]::Now
$endTime = $startTime.AddHours($MMDuration)
$MonitoringClassCG = get-monitoringclass | where {$_.DisplayName -eq $groupName}
$MonitoringGUID = get-monitoringobject $MonitoringClassCG.Id


New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:"ApplicationInstallation" -comment:"none" -monitoringObject:$MonitoringGUID

沒有留言:

張貼留言