Scopus69
2008-06-23 02:43:00 UTC
I am trying to use the following script to put one of my servers in
Maintenance Mode:
param
($rootMS,$computerPrincipalName,$numberOfHoursInMaintenanceMode,$comment)
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"
-ErrorVariable errSnapin;
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable
errSnapin;
set-location $rootMS -ErrorVariable errSnapin;
$computerClass = get-monitoringclass -name:Microsoft.Windows.Computer
$healthServiceClass = get-monitoringclass
-name:Microsoft.SystemCenter.HealthService
$healthServiceWatcherClass = get-monitoringclass
-name:Microsoft.SystemCenter.HealthServiceWatcher
$computerCriteria = "PrincipalName='" + $computerPrincipalName + "'"
$computer = get-monitoringobject -monitoringclass:$computerClass
-criteria:$computerCriteria
$healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass)
$healthService = $healthServices[0]
$healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'"
$healthServiceWatcher = get-monitoringobject
-monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddHours($numberOfHoursInMaintenanceMode)
"Putting " + $computerPrincipalName + " into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime
-monitoringObject:$computer -comment:$comment
"Putting the associated health service into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthService -comment:$comment
"Putting the associated health service watcher into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthServiceWatcher -comment:$comment
I can seem to get it to work. I run the following:
PS C:\> .\AgentMaintenanceMode.ps1 -rootMS: `scomsrv01.acme.com'
-computerPrincipalName: 'websrv02.acme.com' -numberOfHo
ursInMaintenanceMode:1 -comment:'Server is now in MaintenanceMode'
ERROR:
Add-PSSnapin : No Windows PowerShell Snap-ins are available for version 1.
At C:\AgentMaintenanceMode.ps1:3 char:13
+ Add-PSSnapin <<<<
"Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable
errSnapin;
Set-Location : Cannot find a provider with name 'OperationsManagerMonitoring'.
At C:\AgentMaintenanceMode.ps1:4 char:13
+ Set-Location <<<< "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
The term 'new-managementGroupConnection' is not recognized as a cmdlet,
function, operable program, or script file. Ver
ify the term and try again.
At C:\AgentMaintenanceMode.ps1:5 char:30
+ new-managementGroupConnection <<<< -ConnectionString:$rootMS
-ErrorVariable errSnapin;
Set-Location : Cannot find path 'C:\scomsrv01.acme.com' because it does not
exist.
At C:\AgentMaintenanceMode.ps1:6 char:13
+ set-location <<<< $rootMS -ErrorVariable errSnapin;
The term 'get-monitoringclass' is not recognized as a cmdlet, function,
operable program, or script file. Verify the term and try again.
At C:\AgentMaintenanceMode.ps1:8 char:37
+ $computerClass = get-monitoringclass <<<< -name:Microsoft.Windows.Computer
The term 'get-monitoringclass' is not recognized as a cmdlet, function,
operable program, or script file. Verify the te
rm and try again.
At C:\AgentMaintenanceMode.ps1:9 char:42
+ $healthServiceClass = get-monitoringclass <<<<
-name:Microsoft.SystemCenter.HealthService
The term 'get-monitoringclass' is not recognized as a cmdlet, function,
operable program, or script file. Verify the term and try again.
At C:\AgentMaintenanceMode.ps1:10 char:49
+ $healthServiceWatcherClass = get-monitoringclass <<<<
-name:Microsoft.SystemCenter.HealthServiceWatcher
The term 'get-monitoringobject' is not recognized as a cmdlet, function,
operable program, or script file. Verify the t
erm and try again.
At C:\AgentMaintenanceMode.ps1:12 char:33
+ $computer = get-monitoringobject <<<< -monitoringclass:$computerClass
-criteria:$computerCriteria
You cannot call a method on a null-valued expression.
At C:\AgentMaintenanceMode.ps1:13 char:56
+ $healthServices = $computer.GetRelatedMonitoringObjects( <<<<
$healthServiceClass)
Cannot index into a null array.
At C:\AgentMaintenanceMode.ps1:14 char:34
+ $healthService = $healthServices[0 <<<< ]
The term 'get-monitoringobject' is not recognized as a cmdlet, function,
operable program, or script file. Verify the t
erm and try again.
At C:\AgentMaintenanceMode.ps1:16 char:45
+ $healthServiceWatcher = get-monitoringobject <<<<
-monitoringclass:$healthServiceWatcherClass -criteria:$healthServi
ceCriteria
Putting websrv02.acme.com into maintenance mode
The term 'New-MaintenanceWindow' is not recognized as a cmdlet, function,
operable program, or script file. Verify the
term and try again.
At C:\AgentMaintenanceMode.ps1:22 char:22
+ New-MaintenanceWindow <<<< -startTime:$startTime -endTime:$endTime
-monitoringObject:$computer -comment:$comment
Putting the associated health service into maintenance mode
The term 'New-MaintenanceWindow' is not recognized as a cmdlet, function,
operable program, or script file. Verify the
term and try again.
At C:\AgentMaintenanceMode.ps1:26 char:22
+ New-MaintenanceWindow <<<< -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthService -comment:$commen
t
Putting the associated health service watcher into maintenance mode
The term 'New-MaintenanceWindow' is not recognized as a cmdlet, function,
operable program, or script file. Verify the
term and try again.
At C:\AgentMaintenanceMode.ps1:30 char:22
+ New-MaintenanceWindow <<<< -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthServiceWatcher -comment:
$comment
PS C:\>
Maintenance Mode:
param
($rootMS,$computerPrincipalName,$numberOfHoursInMaintenanceMode,$comment)
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"
-ErrorVariable errSnapin;
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable
errSnapin;
set-location $rootMS -ErrorVariable errSnapin;
$computerClass = get-monitoringclass -name:Microsoft.Windows.Computer
$healthServiceClass = get-monitoringclass
-name:Microsoft.SystemCenter.HealthService
$healthServiceWatcherClass = get-monitoringclass
-name:Microsoft.SystemCenter.HealthServiceWatcher
$computerCriteria = "PrincipalName='" + $computerPrincipalName + "'"
$computer = get-monitoringobject -monitoringclass:$computerClass
-criteria:$computerCriteria
$healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass)
$healthService = $healthServices[0]
$healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'"
$healthServiceWatcher = get-monitoringobject
-monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddHours($numberOfHoursInMaintenanceMode)
"Putting " + $computerPrincipalName + " into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime
-monitoringObject:$computer -comment:$comment
"Putting the associated health service into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthService -comment:$comment
"Putting the associated health service watcher into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthServiceWatcher -comment:$comment
I can seem to get it to work. I run the following:
PS C:\> .\AgentMaintenanceMode.ps1 -rootMS: `scomsrv01.acme.com'
-computerPrincipalName: 'websrv02.acme.com' -numberOfHo
ursInMaintenanceMode:1 -comment:'Server is now in MaintenanceMode'
ERROR:
Add-PSSnapin : No Windows PowerShell Snap-ins are available for version 1.
At C:\AgentMaintenanceMode.ps1:3 char:13
+ Add-PSSnapin <<<<
"Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable
errSnapin;
Set-Location : Cannot find a provider with name 'OperationsManagerMonitoring'.
At C:\AgentMaintenanceMode.ps1:4 char:13
+ Set-Location <<<< "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
The term 'new-managementGroupConnection' is not recognized as a cmdlet,
function, operable program, or script file. Ver
ify the term and try again.
At C:\AgentMaintenanceMode.ps1:5 char:30
+ new-managementGroupConnection <<<< -ConnectionString:$rootMS
-ErrorVariable errSnapin;
Set-Location : Cannot find path 'C:\scomsrv01.acme.com' because it does not
exist.
At C:\AgentMaintenanceMode.ps1:6 char:13
+ set-location <<<< $rootMS -ErrorVariable errSnapin;
The term 'get-monitoringclass' is not recognized as a cmdlet, function,
operable program, or script file. Verify the term and try again.
At C:\AgentMaintenanceMode.ps1:8 char:37
+ $computerClass = get-monitoringclass <<<< -name:Microsoft.Windows.Computer
The term 'get-monitoringclass' is not recognized as a cmdlet, function,
operable program, or script file. Verify the te
rm and try again.
At C:\AgentMaintenanceMode.ps1:9 char:42
+ $healthServiceClass = get-monitoringclass <<<<
-name:Microsoft.SystemCenter.HealthService
The term 'get-monitoringclass' is not recognized as a cmdlet, function,
operable program, or script file. Verify the term and try again.
At C:\AgentMaintenanceMode.ps1:10 char:49
+ $healthServiceWatcherClass = get-monitoringclass <<<<
-name:Microsoft.SystemCenter.HealthServiceWatcher
The term 'get-monitoringobject' is not recognized as a cmdlet, function,
operable program, or script file. Verify the t
erm and try again.
At C:\AgentMaintenanceMode.ps1:12 char:33
+ $computer = get-monitoringobject <<<< -monitoringclass:$computerClass
-criteria:$computerCriteria
You cannot call a method on a null-valued expression.
At C:\AgentMaintenanceMode.ps1:13 char:56
+ $healthServices = $computer.GetRelatedMonitoringObjects( <<<<
$healthServiceClass)
Cannot index into a null array.
At C:\AgentMaintenanceMode.ps1:14 char:34
+ $healthService = $healthServices[0 <<<< ]
The term 'get-monitoringobject' is not recognized as a cmdlet, function,
operable program, or script file. Verify the t
erm and try again.
At C:\AgentMaintenanceMode.ps1:16 char:45
+ $healthServiceWatcher = get-monitoringobject <<<<
-monitoringclass:$healthServiceWatcherClass -criteria:$healthServi
ceCriteria
Putting websrv02.acme.com into maintenance mode
The term 'New-MaintenanceWindow' is not recognized as a cmdlet, function,
operable program, or script file. Verify the
term and try again.
At C:\AgentMaintenanceMode.ps1:22 char:22
+ New-MaintenanceWindow <<<< -startTime:$startTime -endTime:$endTime
-monitoringObject:$computer -comment:$comment
Putting the associated health service into maintenance mode
The term 'New-MaintenanceWindow' is not recognized as a cmdlet, function,
operable program, or script file. Verify the
term and try again.
At C:\AgentMaintenanceMode.ps1:26 char:22
+ New-MaintenanceWindow <<<< -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthService -comment:$commen
t
Putting the associated health service watcher into maintenance mode
The term 'New-MaintenanceWindow' is not recognized as a cmdlet, function,
operable program, or script file. Verify the
term and try again.
At C:\AgentMaintenanceMode.ps1:30 char:22
+ New-MaintenanceWindow <<<< -startTime:$startTime -endTime:$endTime
-monitoringObject:$healthServiceWatcher -comment:
$comment
PS C:\>