none
Start-SCOMMaintenanceMode -Instance [Array] is only putting one object into MM from the array RRS feed

  • Question

  • Here is my code snip:
    =================================
    $SCOM = "SCOM.MyDomain.Local"

    Invoke-Command -ComputerName $SCOM -ScriptBlock {
        $Time = Measure-Command{
     Import-Module OperationsManager

            $Minutes = 30
            $Comment = "Test for MM"

    $EndTime = ((Get-Date).AddMinutes($Minutes))
            $ServerArray = @("MyServer1.MyDomain.Local","MyServer2.MyDomain.Local", "SCOM.MyDomain.Local", "NOEXIST.MyDomain.Local")
            $SCOMManagementServers = (Get-SCOMManagementServer).DisplayName

            $Instance = @()
            $Instance = get-SCOMClassInstance -Name $ServerArray

              ForEach ($ManagementServer in $SCOMManagementServers){
                IF ($Instance.DisplayName -contains $ManagementServer){
                    $Instance = $Instance | Where-Object {$_.DisplayName -ne $ManagementServer}
                }
            }
            Start-SCOMMaintenanceMode -Instance $Instance -EndTime $EndTime -Comment $Comment -Reason "SecurityIssue"
            #$Instance.StopMaintenanceMode([DateTime]::Now.ToUniversalTime(),[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive);
        }
        Write-Host $Time
    }

    ======================================

    When ran, only one server is being put into MM.  When I inspect the Instance array, I am seeing MyServer1 and MyServer2, which is correct.  Only MyServer2 is put into MM.  Is there an issue using arrays with Start-SCOMMaintenanceMode?

    Tuesday, May 15, 2018 6:34 PM

Answers

  • As a work around, I was able to do this:

    #Start-SCOMMaintenanceMode -Instance $Instance -EndTime $EndTime -Comment $Comment -Reason "SecurityIssue"

    $Instance.ScheduleMaintenanceMode([DateTime]::Now.ToUniversalTime(),[DateTime]::Now.AddMinutes($Minutes).ToUniversalTime(),"SecurityIssue",$Comment);

    That worked and put all the systems in $Instance into MM.  I think there is a bug with 2016 SCOM's start-SCOMMaintenanceMode cmdlet.

    Tuesday, May 15, 2018 7:17 PM

All replies

  • As a work around, I was able to do this:

    #Start-SCOMMaintenanceMode -Instance $Instance -EndTime $EndTime -Comment $Comment -Reason "SecurityIssue"

    $Instance.ScheduleMaintenanceMode([DateTime]::Now.ToUniversalTime(),[DateTime]::Now.AddMinutes($Minutes).ToUniversalTime(),"SecurityIssue",$Comment);

    That worked and put all the systems in $Instance into MM.  I think there is a bug with 2016 SCOM's start-SCOMMaintenanceMode cmdlet.

    Tuesday, May 15, 2018 7:17 PM
  • Thanks for your sharing.

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, May 16, 2018 2:58 AM
    Moderator