INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SCOM 2012 - Use Powershell to put specific server and contained objects into Maintenance Mode

SCOM 2012 - Use Powershell to put specific server and contained objects into Maintenance Mode

SCOM 2012 - Use Powershell to put specific server and contained objects into Maintenance Mode

(OP)
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:

CODE --> Powershell

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 --> Powershell

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!

RE: SCOM 2012 - Use Powershell to put specific server and contained objects into Maintenance Mode

(OP)
Oops, in the middle there I meant to say:
"The second part, which I know for a fact isn't fully working, is intended to stop maintenance mode for a server."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close