Update: Put OM2012 Computer Group Members in Maintenance Mode with PowerShell


I finally found out the issue why this script was not working for everybody. It was because of the different versions of PowerShell. Now it should also work on PowerShell v2.

Another possible fix to the empty ComputerGroupsMembernames issue.

Last week I saw a request for a PowerShell script which would put all the members of a OM2012 Computer Group in Maintenance Mode, so this could be used with the Task Scheduler.

I know there are quite some alternative when it comes to putting instances in Maintenance Mode, but I thought it would be cool to create the mother-of-all maintenance mode PowerShell scripts for OM2012 🙂

This PowerShell script can be run standalone or scheduled with the Task Scheduler and has the following cool features:

  • Acts as a “real” Cmdlet, with features like:
    • Verbose info
    • Debug info
    • WhatIf switch
  • Help info with Examples
  • Write to Eventlog switch for auditing purposes.
  • No need to run it from the Operations Manager Shell. If the OperationsManager Module is not loaded it will be loaded automatically by the script.

 

Ok enough about the features, here is the script:

#######################################################################################################################             
# Puts a OM2012 Computer Group in Maintenance Mode using PowerShell             
# Author: Stefan Stranger (Microsoft)             
# Example usage: Run Get-Help Get-SCOMMaintenanceModeForGroups.ps1 -Examples            
# Disclamer: This program source code is provided "AS IS" without warranty representation or condition of any kind            
# either express or implied, including but not limited to conditions or other terms of merchantability and/or            
# fitness for a particular purpose. The user assumes the entire risk as to the accuracy and the use of this            
# program code.            
# Tested on PowerShell v3 and OM2012 environment             
# Date: 03-07-2012             
# Name: Get-SCOMMaintenanceModeForGroups.ps1             
# v1.000 - 03-07-2012 - Stefan Stranger - initial sstranger's release            
# v1.001 - 06-07-2012 - Stefan Stranger - Added Eventlog and WhatIf Switch 
# v1.003 - 07-11-2012 - Stefan Stranger - Fixed issue on PowerShell v2, Now works on v2 and v3 # v1.004 - 16-11-2012 - Stefan Stranger - Fixed issue with empty GroupMembershipNames issue
######################################################################################################################## <# .SYNOPSIS Places all members of a SCOM Computer Group in into maintenance mode, and creates new active maintenance mode entries. .DESCRIPTION The Start-MaintenanceModeForGroups script places all members of a SCOM Computer Group into maintenance mode, and creates new active maintenance mode entries. When in maintenance mode, alerts, notifications, rules, monitors, automatic responses, state changes, and new alerts are suppressed for the class instance. .EXAMPLE Start-SCOMMaintenanceModeForGroup.ps1 -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -Verbose Puts all Members of the "All Windows Computer" Group in Maintenance Mode for 10 minutes, with Reason "UnplannedOther" and with Comment "Testing Maintenance Mode". Adding Verbose information. .EXAMPLE Start-SCOMMaintenanceModeForGroup.ps1 -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -Eventlog Puts all Members of the "All Windows Computer" Group in Maintenance Mode for 10 minutes, with Reason "UnplannedOther" and with Comment "Testing Maintenance Mode". Writing Eventlog information to the "Operations Manager" Eventlog (eventid 998 and eventid 999). Can be used for tracking and debugging when Task Scheduler is being used. .EXAMPLE Start-SCOMMaintenanceModeForGroup.ps1 -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -WhatIf Using the WhatIf switch shows which Members of the "All Windows Computer" Group would be put in Maintenance Mode if you had run the script. So the members are not really put into maintenance mode. For testing purposes. .PARAMETER ComputerGroup The SCOM Computer Group name for which members you want to put in Maintenance Mode. .PARAMETER EndTime Specifies the time the maintenance will end. The minimum amount of time a resource can be in maintenance mode is 5 minutes. .PARAMETER Reason Specifies the reason for placing the resource into maintenance mode. Valid values are: UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation, UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration, UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance, ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable, SecurityIssue, LossOfNetworkConnectivity .Parameter Comment Allows you to type a comment about the maintenance activity. .Parameter EventLog Writes information to the "Operations Manager" Eventlog to track what is happening. .Link http://blogs.technet.com/stefan_stranger#> #requires -version 2.0 [CmdletBinding(SupportsShouldProcess=$true)] param ( [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='What is the ComputerGroup you want to put in Maintenance Mode?')] [Alias("Group")] [string[]]$ComputerGroup, [Parameter(Mandatory=$True, ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$True, HelpMessage='Specifies the time the maintenance will end. The minimum amount of time a resource can be in maintenance mode is 5 minutes. This is a required parameter')] [int]$EndTime, [Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation, UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration, UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance, ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable, SecurityIssue, LossOfNetworkConnectivity')] [string]$Reason, [Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='Allows you to type a comment about the maintenance activity.')] [string]$Comment, [switch]$EventLog ) set-strictmode -version latest $start=Get-Date $currentlog = $start.ToString() Write-Verbose "Starting $($myinvocation.mycommand)" Write-Verbose "Ready to put ComputerGroup $ComputerGroup in Maintenance Mode" Function Start-SCOMMaintenanceModeForGroup { <# .SYNOPSIS Sets a SCOM Group in Maintenance Mode .DESCRIPTION Sets the members of a SCOM Group in Maintenance Mode .EXAMPLE Start-SCOMMaintenanceModeForGroup -ComputerGroup "All Windows Computers" -EndTime 10 -Reason "UnplannedOther" -Comment "Testing Maintenance Mode" -Verbose .PARAMETER ComputerGroup The SCOM Computer Group name for which members you want to put in Maintenance Mode. .PARAMETER EndTime Specifies the time the maintenance will end. The minimum amount of time a resource can be in maintenance mode is 5 minutes. .PARAMETER Reason Specifies the reason for placing the resource into maintenance mode. Valid values are: UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation, UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration, UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance, ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable, SecurityIssue, LossOfNetworkConnectivity .Parameter Comment Allows you to type a comment about the maintenance activity. .Link http://blogs.technet.com/stefan_stranger #> [CmdletBinding(SupportsShouldProcess=$true)] param ( [Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='What is the ComputerGroup you want to put in Maintenance Mode?')] [Alias("Group")] [string[]]$ComputerGroup, [Parameter(Mandatory=$True, ValueFromPipeline=$false, ValueFromPipelineByPropertyName=$True, HelpMessage='Specifies the time the maintenance will end. The minimum amount of time a resource can be in maintenance mode is 5 minutes. This is a required parameter')] [int]$EndTime, [Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='UnplannedOther, PlannedHardwareMaintenance, UnplannedHardwareMaintenance, PlannedHardwareInstallation, UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration, UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance, ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable, SecurityIssue, LossOfNetworkConnectivity')] [string]$Reason, [Parameter(Mandatory=$False, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True, HelpMessage='Allows you to type a comment about the maintenance activity.')] [string]$Comment, [switch]$EventLog ) Begin { Write-Verbose "Starting Function Start-SCOMMaintenanceModeForGroup Function" #Check for minumum Maintenance mode period of 5 mins. if($endtime -lt 5) { Write-Error "The time span for the maintenance mode should be at least 5 minutes." -ErrorAction Stop } Write-Verbose "Following Group Members will be put in Maintenance Mode:" $ComputerGroupMembers = Get-SCOMMonitoringObject -DisplayName $ComputerGroup if($ComputerGroupMembers) { #$ComputerGroupMemberNames = ($ComputerGroupMembers.getrelatedMonitoringObjects() | select DisplayName).DisplayName
$ComputerGroupMemberNames = ($ComputerGroupMembers.getrelatedMonitoringObjects() | select DisplayName)
Write-Verbose "$ComputerGroupMemberNames" #Retrieve Management Servers so we can check if we don't put Management Servers in MM. $MSs = Get-SCOMManagementServer } else { Write-Error "No Members of ComputerGroup $ComputerGroup found" -ErrorAction Stop } } #End Begin Process { #Put Agents in Maintenance Mode foreach ($agent in $ComputerGroupMembers.getrelatedMonitoringObjects()) { Write-Verbose "Checking if ComputerGroup Member $agent is not a Management Server" if(($MSs | Select DisplayName) -eq $agent) { Write-Verbose "We don't want to put a Management Server in MM. Skipping" } else { Write-Verbose "Let's put Agent $Agent in Maintenance Mode" $Instance = Get-SCOMClassInstance -Name $Agent if ($PSCmdlet.ShouldProcess("Putting $Agent in Maintenande Mode for $($Endtime) minutes") ) { #Added 5 seconds to EndTime to prevent failing the Start-SCOMMaintenanceMode cmdlet. Min. 5 mins is needed. Start-SCOMMaintenanceMode -Instance $Instance -EndTime ([System.DateTime]::Now).AddSeconds(5).addMinutes($EndTime) -Reason $Reason -Comment $Comment }#End of whatif }#End of else }#End Foreach if ($PSBoundParameters['EventLog']) { write-eventlog -LogName "Operations Manager" -Source "OpsMgr SDK Service" -EventID 999 -message "The following Objects are put into in Maintenance Mode for $($EndTime) minutes: $($ComputerGroupMembers.getrelatedMonitoringObjects())" }#End if } #End Process End { Write-Verbose "Finished Function Start-SCOMMaintenanceModeForGroup Function" } } #Main try { if ($PSBoundParameters['EventLog']) { write-eventlog -LogName "Operations Manager" -Source "OpsMgr SDK Service" -EventID 998 -message "The $($myinvocation.mycommand) is used to put Objects in Maintenance Mode" } Write-Verbose "Checking if OperationsManager Module is loaded" #Check if OperationsManager Module is loaded. if(!(Get-Module OperationsManager)) { Write-Verbose "Importing OperationsManager Module" Import-Module OperationsManager -ErrorAction Stop } Write-Verbose "Checking for OM2012 environment" #Check if OM2012 is being used. if(!(Get-Module OperationsManager).Description -eq "Operations Manager OperationsManagerV10 Module") { Write-Error "This script is only for OM2012" } #Call Function if ($PSBoundParameters['EventLog']) { Start-SCOMMaintenanceModeForGroup -ComputerGroup $ComputerGroup -EndTime $EndTime -Reason $Reason -Comment $Comment -EventLog } else { Start-SCOMMaintenanceModeForGroup -ComputerGroup $ComputerGroup -EndTime $EndTime -Reason $Reason -Comment $Comment } } #End Try catch [System.IO.FileNotFoundException] { "OperationsManager Module not found" $_.Exception.Message } catch { Write-Warning "Oops something went wrong" $_.Exception.Message } $end=Get-Date Write-Debug ("Total processing time {0}" -f ($end-$start).ToString()) Write-Verbose "Ending $($myinvocation.mycommand)"

 

You can use the Get-Help Get-SCOMMaintenanceModeForGroups.ps1 –full command in PowerShell to see the complete help for this script.

image

Example using the –WhatIf switch

image

Let’s do the real deal and put some members of my “Stefan – OM2012 Maintenance Computer Group” in Maintenance Mode for 5 minutes.

image

Result:

image

image

 

How do use this cool PowerShell script to schedule Maintenance Mode using the Task Scheduler?

Steps:

    1. Save script as: D:\Scripts\OM2012\Start-SCOMMaintenanceModeForGroups.ps1

    2. Open TaskScheduler (on OM2012 Management Server or where you have installed the Operations Manager Console)
      image

    3.  

      Create a new Task
      image

       

    4. Enter Name and make sure the user account under which the Scheduled Task is running is having enough permissions in SCOM. Select Run with Highest privileges.
      image

    5. Configure Trigger
      image

    6. Add action

      Program/script: powershell.exe

      Add argument (optional): D:\Scripts\OM2012\Start-SCOMMaintenanceModeForGroups.ps1 -ComputerGroup ‘Stefan – OM2012 Maintenance Computer Group’ -EndTime 5 -Reason “UnplannedOther” –Comment ‘Testing MM’ -Eventlog

      Remark: Make sure you use single quotes of ComputerGroup, Reason or Comment Parameters if space are being used in the name.

      image

    7. Enter Credentials

      clip_image001

      clip_image002

      clip_image003

If you have scheduled to script using the EventLog Switch toy can look in the Operations Manager Eventlog for auditing info.
image

You can download the script from the Script Center Repository: http://gallery.technet.microsoft.com/scriptcenter/Put-OM2012-Computer-Group-43902672

Have fun!

Comments (31)

  1. Anonymous says:

    I wonder if this script ever worked.

    You have to do some modifications to get it running:

    1) $ComputerGroupMembers.getrelatedMonitoringObjects().DisplayName does not work, so use:

               $ComputerGroupMemberNames = $ComputerGroupMembers.getrelatedMonitoringObjects()          

               Write-Verbose "$ComputerGroupMemberNames"

    2) If you have more than 1 manager:

               Write-Verbose "Checking if ComputerGroup Member $agent is not a Management Server"

    $IsMS = 0

    foreach ($manager in $MSs)

    {

    if(($manager | Select DisplayName).displayname -eq $agent)            

    {            

    Write-Verbose "We don't want to put a Management Server in MM. Skipping"  

    $IsMS = 1

    }  

    }

               if ( $IsMS -eq 0 )        

               {            

                   Write-Verbose "Let's put Agent $Agent in Maintenance Mode"

    ….

    3) No need for "$Instance = Get-SCOMClassInstance -Name $Agent", because Start-SCOMMaintenanceMode needs $Agent instead of $Instance!

    So, modify:

    Start-SCOMMaintenanceMode -Instance $Agent -EndTime ([System.DateTime]::Now).AddSeconds(5).addMinutes($EndTime) -Reason $Reason -Comment $Comment

    4) Comment and Reason are not defined as mandatory, but are needed!

    So add following lines to define defaults:

       #Call Function            

    if ( $Reason -eq "" )

    {

    $Reason = "PlannedApplicationMaintenance"

    }

    if ( $Comment -eq "" )

    {

    $Comment = "Scheduled Maintenance"

    }

    Regards, Werner

  2. Anonymous says:

    Hi Guys,

    I'm sorry if the script is not working. I've tested the script in my environment and it worked in my environment. But will look at your comments soon.

    /Stefan

  3. Anonymous says:

    I am testing this on SCOM 2012 SP1 installed on server 2012 and the script fails to detect the management servers when it runs. As a result all the servers go into maintenance, including the management ones and my maintenance mode never ends.

  4. Anonymous says:

    The script works fine in my environment after a shot time debug. you need remove the comment symbol "#" and repeat code "$ComputerGroupMemberNames = ($ComputerGroupMembers.getrelatedMonitoringObjects() | select DisplayName).DisplayName" from loop statement
    of the script. I have put the fixed loop statement as below:

    Begin
    {
    Write-Verbose "Starting Function Start-SCOMMaintenanceModeForGroup Function"
    #Check for minumum Maintenance mode period of 5 mins.
    if($endtime -lt 5)
    {
    Write-Error "The time span for the maintenance mode should be at least 5 minutes." -ErrorAction Stop

    }
    Write-Verbose "Following Group Members will be put in Maintenance Mode:"
    $ComputerGroupMembers = Get-SCOMMonitoringObject -DisplayName $ComputerGroup
    if($ComputerGroupMembers)
    {
    $ComputerGroupMemberNames = ($ComputerGroupMembers.getrelatedMonitoringObjects() | select DisplayName)

    Write-Verbose "$ComputerGroupMemberNames"
    #Retrieve Management Servers so we can check if we don’t put Management Servers in MM.

    $MSs = Get-SCOMManagementServer
    }
    else
    {
    Write-Error "No Members of ComputerGroup $ComputerGroup found" -ErrorAction Stop
    }
    } #End Begin

  5. Anonymous says:

    Stefan, thanks for the script, could you please verify if this script can be run from a remote (shared desktop) with SCOM console and ops Mgr shell installed or it will only work from a Management Server?

  6. Anonymous says:

    Hi Vijah,

    Right now I don't have an idea why it fails but you could start adding -erroraction Stop after each Start-SCOMMaintenanceMode cmdlet call in the script and see if that part is failing when running it from the taskscheduler.

    Stefan

  7. Anonymous says:

    Nice Post Stefan!

  8. Anonymous says:

    Thanks!

  9. Anonymous says:

    Hi John,

    For ending the Maintenance mode you should have a look at the Set-SCOMMaintenanceMode Cmdlet. Start with looking at the help for this Cmdlet. Get-Help Set-SCOMMaintenanceMode

    /Stefan

  10. Anonymous says:

    Thanks Very Much Stefan,

    It was a shame to see the Maintenance Mode Scheduler from 2007R2 be deprecated. This is very useful, works great for most computers, however I have a number of SQL cluster nodes where like Ernie I get the script halting and failing to continue with the rest of the estate. Will I need to look to create an exception for these clustered nodes within the dynamic group population, or do we need to make an amendment to the script to target it at different SCOM classes?

    WARNING: Oops something went wrong Cannot validate argument on parameter 'Instance'. The argument is null. Supply a non-null argument and try the command again.

  11. Anonymous says:

    The script works fine in my environment after a shot time debug. you need remove the comment symbol "#" and repeat code "$ComputerGroupMemberNames = ($ComputerGroupMembers.getrelatedMonitoringObjects() | select DisplayName).DisplayName" from loop statement
    of the script. I have put the fixed loop statement as below:

    Begin
    {
    Write-Verbose "Starting Function Start-SCOMMaintenanceModeForGroup Function"
    #Check for minumum Maintenance mode period of 5 mins.
    if($endtime -lt 5)
    {
    Write-Error "The time span for the maintenance mode should be at least 5 minutes." -ErrorAction Stop

    }
    Write-Verbose "Following Group Members will be put in Maintenance Mode:"
    $ComputerGroupMembers = Get-SCOMMonitoringObject -DisplayName $ComputerGroup
    if($ComputerGroupMembers)
    {
    $ComputerGroupMemberNames = ($ComputerGroupMembers.getrelatedMonitoringObjects() | select DisplayName)

    Write-Verbose "$ComputerGroupMemberNames"
    #Retrieve Management Servers so we can check if we don’t put Management Servers in MM.

    $MSs = Get-SCOMManagementServer
    }
    else
    {
    Write-Error "No Members of ComputerGroup $ComputerGroup found" -ErrorAction Stop
    }
    } #End Begin

  12. Rich Ellis says:

    I keep getting this error:

    PS C:> C:!ScriptsStart-SCOMMaintenanceModeForGroups.ps1 -ComputerGroup 'Maintenance Mode – Friday 4AM' -EndTime 5 -Re

    ason "UnplannedOther" -Comment 'Testing MM' -Eventlog

    WARNING: Oops something went wrong

    Property 'DisplayName' cannot be found on this object. Make sure that it exists.

    Any idea why?

  13. JW says:

    I get the same error too.

  14. Script tested says:

    Hi guys,

    Today I tested my script which I downloaded from the Script Center Repository and run the following:

    PS D:ScriptsOM2012Online> .Start-SCOMMaintenanceModeForGroups.ps1 -ComputerGroup "All Windows Computers" -EndTime 10-Reason "UnplannedOther" -Comment "Testing" -Verbose

    I just put all my agents in my "All Windows Computer" Group in Maintenance mode.

    @Rich:

    Can you run the same command but with the -Verbose Switch on? And let me know where it fails?

    @JW:

    Can you run the same command but with the -Verbose Switch on? And let me know where it fails?

    @Werner:

    When I check the methods and properties of the $ComputerGroupMembers variable I see the following:

    [DBG]: PS D:ScriptsOM2012Online>> $ComputerGroupMembers.getrelatedMonitoringObjects()

    HealthState     InMaintenanceMode  DisplayName                                            

    ———–     —————–  ———–                                            

    Error                 False        W2K8R2DC1.DEMO.STRANGER                                

    Success               False        OM12DMZ01.demo.dmz                                    

    Warning               False        OM12MS02.DEMO.STRANGER                                

    Warning               False        OM12MS01.DEMO.STRANGER                                

    [DBG]: PS D:ScriptsOM2012Online>> $ComputerGroupMembers.getrelatedMonitoringObjects().DisplayName

    W2K8R2DC1.DEMO.STRANGER

    OM12DMZ01.demo.dmz

    OM12MS02.DEMO.STRANGER

    OM12MS01.DEMO.STRANGER

    So I there is a property DisplayName (in my environment)

    And regarding multiple Management Servers, I've multiple Management Servers and with the following PowerShell code I am checking multiple MS if they are not Agents.

    if(($MSs | Select DisplayName).displayname -eq $agent)

    {

       Write-Verbose "We don't want to put a Management Server in MM. Skipping"

    }

    Try the following in PowerShell:

    $testagents = "test1", "test2", "test3"

    $testmss = "test1", "test4", "test5"

    foreach ($agent in $testagents)

    {

       Write-Host "Checking if ComputerGroup Member $agent is not a Management Server"

       if($testmss  -eq $agent)

       {

           Write-Host "We don't want to put a Management Server: $agent in MM"

       }

       else

       {

           Write-Host "Let's put Agent $Agent in Maintenance Mode"

       }#End of else

    }#End Foreach

    Will look at all your other comments later this week.

    /Stefan

  15. adam says:

    When targeted at a Windows Computer object puts only that object into maintenance mode ie does not puts all contained objects into maintenance mode.

  16. Hi Adam,

    What is not working correctly? Could you please expand a little bit on what is failing according too you?

    /Stefan

  17. bkhsms says:

    I really like the script, but had to do some modifications to get it to work.  I debugged the script in PS for the Get-SCOMMonitoringObject which according to the SDK is an alias to the Get-SCOMClassInstance cmdlet.  According to that you have to identify the -Group tack in order to pass the intent to work in the Group class.  I bypassed that by using the Get-SCOMGroup cmdlet and dropped the .DisplayName from the $ComputerGroupMembers.getrelatedMonitoringObjects() section.  I then passed DisplayName through the Write-Verbose portion by tacking it on to "ComputerGroupMemberNames.DisplayName" .  I have two management servers and took your advice to statically define them in the $MSs parm.  I then dropped the pipe in the loop and just did a ($MSs -eq $agent) which works like a champ.

    Thanks again!!

  18. SCOM Hustla says:

    I've tried to get this to work but it just doesn't.  I'm still using the old 2007 r2 script for 2012 which works but is uglier.

    To those that have made all the changes and claim it now works it would be nice to share the script.

    Stefan's out of the box script is not working as written in 2 different 2012 env I've tested.

    Appreciate everyone's efforts on this, especially Stefan's!

  19. Matt says:

    Same problem here.

    PS D:scripts> .Start-SCOMMaintenanceModeForGroups.ps1 -ComputerGroup "GTS MM Test Group" -Endtime 10 -reason "Unplanne

    dOther" -Comment "Cause" -verbose

    VERBOSE: Starting Start-SCOMMaintenanceModeForGroups.ps1

    VERBOSE: Ready to put ComputerGroup GTS MM Test Group in Maintenance Mode

    VERBOSE: Checking if OperationsManager Module is loaded

    VERBOSE: Checking for OM2012 environment

    VERBOSE: Starting Function Start-SCOMMaintenanceModeForGroup Function

    VERBOSE: Following Group Members will be put in Maintenance Mode:

    WARNING: Oops something went wrong

    Property 'DisplayName' cannot be found on this object. Make sure that it exists.

    VERBOSE: Ending Start-SCOMMaintenanceModeForGroups.ps1

  20. Kiwifulla says:

    Yep, same DisplayName issues as most with the script 🙁

  21. Maarten Hordijk says:

    Yep tested and working correctly 🙂 Will be implementing this in our environment. Thanks!

  22. Seth Technet says:

    Getting the same error as Matt:

    VERBOSE: Starting Start-SCOMMaintenanceModeForGroups_v3.ps1

    VERBOSE: Ready to put ComputerGroup ScheduledMM in Maintenance Mode

    VERBOSE: Checking if OperationsManager Module is loaded

    VERBOSE: Checking for OM2012 environment

    VERBOSE: Starting Function Start-SCOMMaintenanceModeForGroup Function

    VERBOSE: Following Group Members will be put in Maintenance Mode:

    WARNING: Oops something went wrong

    Property 'displayname' cannot be found on this object. Make sure that it exists.

    VERBOSE: Ending Start-SCOMMaintenanceModeForGroups_v3.ps1

    PS D:scripts> .Start-SCOMMaintenanceModeForGroups_v3.ps1 -ComputerGroup 'ScheduledMM' -EndTime 5 -Reason "UnplannedOth

    er" -Comment 'Testing MM' -Eventlog -Debug

    WARNING: Oops something went wrong

    Property 'displayname' cannot be found on this object. Make sure that it exists.

    DEBUG: Total processing time 00:00:00.1980000

  23. Seth Technet says:

    To provide more context, I only have one MS in this environment (2 in prod though) and multiple computers I'm trying to put in maintenance mode in the group ScheduledMM.  All computers are of Microsoft.Windows.Computer class.

  24. SCOM Hustla says:

    Thanks for the update, its working great, unfortunately though this put 2 of my Management Servers into Maint Mode when using the ALL Windows Computers group.

    Any ideas to avoid this? Luckily 2012 handles this bad practice (putting an MS into MM) better than 2007R2.

    🙂

  25. Ernie says:

    Script chokes on SQL Node Computer objects. Please update if you have the time … 🙂

    VERBOSE: Let's put Agent Z1SQLNODE01 in Maintenance Mode

    WARNING: Oops something went wrong Cannot validate argument on parameter 'Instance'. The argument is null. Supply a non-null argument and try the command again.

  26. Rob Hull says:

    This script works in that it put the servers in a group into maintenance mode … brilliant however I still receive alerts if I stop one of the application services.

    If I Put the sever into Maintenance mode from the Ops Mgr I don not receive these alerts. I have looked in the Ops Mgr when the script has worked and everything appears correct any ideas?

  27. Johan says:

    Does this work for groups containing any type of objects, or does it have to be computers? I tried creating a group with a number of Web applications in it, and then ran the script.

    PS C:work> .Start-SCOMMaintenanceModeForGroups.ps1 "Backup Window maintenance" -EndTime 5 -Reason "PlannedOther" -Comment "Testing" -Verbose

    VERBOSE: Starting Start-SCOMMaintenanceModeForGroups.ps1

    VERBOSE: Ready to put ComputerGroup Delta Veeam Window maintenance in Maintenance Mode

    VERBOSE: Checking if OperationsManager Module is loaded

    VERBOSE: Checking for OM2012 environment

    VERBOSE: Starting Function Start-SCOMMaintenanceModeForGroup Function

    VERBOSE: Following Group Members will be put in Maintenance Mode:

    VERBOSE:

    VERBOSE: Checking if ComputerGroup Member web check is not a Management Server

    VERBOSE: Let's put Agent web.port.se check in Maintenance Mode

    WARNING: Oops something went wrong

    Cannot validate argument on parameter 'Instance'. The argument is null. Supply a non-null argument and try the command again.

    VERBOSE: Ending Start-SCOMMaintenanceModeForGroups.ps1

    It works if I only have computer objects in the group.

  28. Vijayh says:

    Hello,

    The script is working fine and place the server into maintenance mode without any issues, when i schedule it in task scheduler and it ran successfully but not placing the server into maintenance mode. No errors are also triggered and in history it show all information events that the task completed successfully.

    Could anyone please help me what may wrong in schedule task..

  29. Stefan says:

    Hi Shifak,

    For testing I implemented the WhatIf switch.

    That would have given you information about the servers that would have been put in MM.

    Stefan

  30. john nguyen says:

    Hi there,

    your script is working great, but i was wondering if you had anything that would take the group out of maintenance mode on demand? so if you needed to take the group out of maint mode before the end of the duration that was originally set.

    thanks!

    JN

  31. steven says:

    how can we modify the the script so that it can run the maintenance mode for group of servers in others format such as .txt file.