I am trying to develop what I thought was going to be an easy script, to put a specific server and all it's contained objects into maintenance mode in SCOM 2012. Not a group, but just one specific server and all it's stuff.
My script to START maintenance mode has two parameters:
1. The FQDN. So for example: server1.contoso.com
2. The amount of minutes to put into maintenance mode
Then it does the following to START maintenance mode:
This seems to work from what I can tell. I know that when you schedule maintenance mode manually in SCOM, there is an option to apply to "Selected objects and all their contained objects". I do not know if that is occurring based on my code above. But I think that is what I want to happen. I just want all monitoring and alerting for the specified server to stop. So if you think I need to change the above code so that it gets all the "contained objects" please let me know.
The second part, which I know for a fact is to stop maintenance mode for a server.
My script to STOP maintenance mode has only one parameter:
1. The FQDN. So for example: server1.contoso.com
Then it does the following to STOP maintenance mode:
This part does seem to work partially. It does remove the server from maintenance mode. However, I suspect that it's not removing all the "contained objects" from maintenance mode because when I run the script to stop maintenance mode on a server, the little maintenance mode icon in SCOM does go away but the overall light for the server stays set to "Not Monitored". It never turns back to the green checkbox and says "Healthy". When I start and stop maintenance mode manually I can see that the green Healthy checkbox comes back. But when I try to run my above code to do it via script, it stays at "Not Monitored" instead.
Can someone help me out here? Looking for answers to two questions:
1. Does my Start maintenance mode code look ok? Will that put a server and all it's contained objects into maintenance mode?
2. What do I need to hadd to my Stop maintenance mode code, so that it correctly stops maintenance mode on the server and all its objects and everything starts to be monitored again?
Thanks in advance! Please let me know if you need any more information in order to be able to help me!
My script to START maintenance mode has two parameters:
1. The FQDN. So for example: server1.contoso.com
2. The amount of minutes to put into maintenance mode
Then it does the following to START maintenance mode:
Code:
Import-Module OperationsManager
$Instance = Get-SCOMClassInstance -Name $FQDN
If ($Instance)
{
$newEnd = ((Get-Date).AddMinutes($minutes))
Start-SCOMMaintenanceMode -Instance $Instance -end $newEnd -Reason "PlannedOther" -Comment "Comments here"
}
This seems to work from what I can tell. I know that when you schedule maintenance mode manually in SCOM, there is an option to apply to "Selected objects and all their contained objects". I do not know if that is occurring based on my code above. But I think that is what I want to happen. I just want all monitoring and alerting for the specified server to stop. So if you think I need to change the above code so that it gets all the "contained objects" please let me know.
The second part, which I know for a fact is to stop maintenance mode for a server.
My script to STOP maintenance mode has only one parameter:
1. The FQDN. So for example: server1.contoso.com
Then it does the following to STOP maintenance mode:
Code:
Import-Module OperationsManager
$Instance = Get-SCOMClassInstance -Name $FQDN
If ($Instance)
{
$MMEntry = Get-SCOMMaintenanceMode -Instance $Instance
If ($MMentry)
{
#basically sends an end time of 1 minute from when the script is run
$newEnd = ((Get-Date).AddMinutes(1))
Set-SCOMMaintenanceMode -MaintenanceModeEntry $MMEntry -EndTime $NewEnd -Comment "Removing from Maintenance Mode" }
}
This part does seem to work partially. It does remove the server from maintenance mode. However, I suspect that it's not removing all the "contained objects" from maintenance mode because when I run the script to stop maintenance mode on a server, the little maintenance mode icon in SCOM does go away but the overall light for the server stays set to "Not Monitored". It never turns back to the green checkbox and says "Healthy". When I start and stop maintenance mode manually I can see that the green Healthy checkbox comes back. But when I try to run my above code to do it via script, it stays at "Not Monitored" instead.
Can someone help me out here? Looking for answers to two questions:
1. Does my Start maintenance mode code look ok? Will that put a server and all it's contained objects into maintenance mode?
2. What do I need to hadd to my Stop maintenance mode code, so that it correctly stops maintenance mode on the server and all its objects and everything starts to be monitored again?
Thanks in advance! Please let me know if you need any more information in order to be able to help me!