locked
Maintenance Mode Madness - PowerShell and Windows & Linux (SCOM 2012 R2 UR12) RRS feed

  • Question

  • I've written a script to put servers into MM remotely via PoSh through automated tools that perform maintenance on servers in the wee hours.

    Originally, I wrote the script to start MM using Get-SCOMClass -ComputerName $SCOMServer -name:Microsoft.Windows.Computer as the class of the instance object I was putting in MM. This worked, until...

    We also had a need to put Linux/Unix computers in MM, too.

    So I edited the script to use Get-SCOMClass -ComputerName $SCOMServer -name:System.Computer

    This seems to work fine for Start-SCOMMaintenanceMode, but if I use Set-SCOMMaintenanceMode, on the Windows computers, only the base class instance is taken out of MM, not anything below it in the class hierarchy. So essentially the computer object shows as unmonitored, but not in MM, and everything under that object remains in MM.

    Any ideas? I'd hate to write a script with a bunch of checking to see if the object to be put into MM is a Linux or Windows server and conditionally execute sections of script.

    Thursday, August 23, 2018 10:46 PM

Answers

All replies

  • Hi,

    You may try the following to see if it works.

    $instances = get-scomgroup | where {$_.displayname -like "test02"}
    $time ((get-date)).addhours((24))
    start-scomMaintenanceMode -instance $instances -endtime $time -reason "PlannedHardwareMaintenance" -Comment "core network upgrade"

    If the above fails, I'm afraid we may need separate code blocks for Widows and Linux computers.

    Putting Unix/Linux servers in MM with Powershell
    http://opsmode.com/2011/02/putting-unixlinux-servers-in-mm-with-powershell/

    Hope the above information helps.

    Regards,

    Alex Zhu
    -----------------------------------------------
    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
    Friday, August 24, 2018 1:44 AM
  • I've actually done some additional testing with this. I've used a couple of different scripts, working with System.Computer and Microsoft.Windows.Computer.

    The problem is that (suddenly, as this same script worked before at the same UR level, 12) they no longer take contained objects out of MM. Only the parent object is removed from MM. HOWEVER, when Start-SCOMMaintenanceMode is used, the parent and all contained objects are put into MM.

    Essentially, they look like this. The first will put a Windows computer and all contained objects into MM:

            $Instance = Get-SCOMClassInstance -ComputerName $SCOMServer -Class $ComputerClass | where { $_.'[Microsoft.Windows.Computer].DNSName' -match "$ComputerName"}
    
            If ($Instance.Name){ 
    
                #Place the object in Maintenance Mode.
                Start-SCOMMaintenanceMode -Instance $Instance -EndTime $EndTime -Reason $Reason -Comment $Comment
                } 

    This one will put both Linux and Windows computers and all the objects in the hierarchy same as above, into MM:

            $Instance = Get-SCOMClassInstance -Class $ComputerClass | WHERE { $_.'[System.Entity].DisplayName' -match "$ComputerName" }
    
            If ($Instance.Name){ 
    
                #Place the object in Maintenance Mode.
                Start-SCOMMaintenanceMode -Instance $Instance -EndTime $EndTime -Reason $Reason -Comment $Comment
                } 

    The only "key" is the setting of $ComputerClass. In case one it's like this:

    $ComputerClass = Get-SCOMClass -ComputerName $SCOMServer -name:Microsoft.Windows.Computer

    In the second case, it's like this:

    $ComputerClass = Get-SCOMClass -name:System.Computer

    It's really just a question of setting the class of object you want to put in MM, and System.Computer contains all computer objects, Windows, UNIX, or Linux.

    The trouble is, when you use this command (Set-SCOMMaintenanceMode is the only means I am aware of to modify an existing MM):

            $Instance = Get-SCOMClassInstance -Class $ComputerClass | WHERE { $_.'[System.Entity].DisplayName' -match "$ComputerName" }
    
            If ($Instance.Name){ 
    
                #Place the object in Maintenance Mode.
                #Start-SCOMMaintenanceMode -Instance $Instance -EndTime $EndTime -Reason $Reason -Comment $Comment
    
                Get-SCOMMaintenanceMode -Instance $Instance | Set-SCOMMaintenanceMode –EndTime (Get-Date) –Comment $Comment

    It doesn't matter what you have set computer class to, it takes the parent object out of MM fine - but none of the contained objects are taken out of MM, so it puts the parent object effectively into an "Unmonitored" state, with nothing below it in the hierarchy being monitored.

    This is new behavior. We've been using these for some time, and this is a fairly recent development. Nothing has been updated or modified in the SCOM environment since this was started in use.



    • Edited by HS Brown Friday, August 24, 2018 8:26 PM
    Friday, August 24, 2018 8:21 PM
  • Found this hidden gem:

    https://blogs.technet.microsoft.com/ralphkyttle/2014/11/10/scom-2012-r2-use-powershell-to-end-an-active-maintenance-mode/

    This is the "proper" way to end MM as near as I can tell.

    • Marked as answer by HS Brown Friday, August 24, 2018 10:07 PM
    Friday, August 24, 2018 9:23 PM