"Class instance is already in Maintenance Mode" - but it isn't

Hello,
we have a powershell script to set the servers managed by scom agent in maintenance mode (e.g. for windows updates and restart).
A colleague recognized an error during running this script. It says that instances of the server are still in maintenance mode. But if you check through SCOM it is not. And for resetting maintenance mode with 0 it says it is not in maintenance mode.
Is it possible to clear maintenance mode for all things wiht a sql statement?
Script:
#=============================================================================#
# Remote-MaintenanceModeV5.ps1 #
# Powershell Script to put a SCOM agent into maintenance mode. #
# Autor: Roman Strecker #
# Date: 14.12.2012 #
# Bekannte Fehler: Speicher auf dem Zielhost (SCOM) muss hoehergesetzt werden!#
# winrm set winrm/config/winrs `@`{MaxMemoryPerShellMB=`"512`"`} #
#=============================================================================#
param(
[Parameter(Mandatory = $false)][string]$ComputerName,
[Parameter(Mandatory = $false)][string]$Dauer
Function SetMaintenanceMode
$ok = Test-Connection 10.202.14.29 -Count 1 -Quiet
if (-not($ok)) {
$SCOMServer = "srv14v030"
else{
$SCOMServer = "srv14v029"
#Kleinster Zeitinterval bei SCOM sind 6 Minuten!
if ([int]$Dauer -eq '0') {
Write-Host "Löschen des Maintenance Modes wird durchgeführt!"
$DeleteMM = $true
else {
if ([int]$Dauer -lt '6') {
$Dauer = "6"
$startTime = [DateTime]::Now
$endTime = $startTime.AddMinutes($Dauer)
Write-Host "`nFolgende Parameter werden verwendet: `nServername: $ComputerName `nWartungs-Dauer: $Dauer Minuten `nWartungsmodus wird geprüft..."
#Get-ChildItem env:
#Erzeuge ein Credential-Objekt für die Verbindung zum SCOM:
$secpasswd = ConvertTo-SecureString "xxxxxx" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ("SA_SCOM-ActionAcc", $secpasswd)
#Erzeuge eine Remote-Session zum SCOM:
#$Session = New-PSSession -ComputerName $SCOMServer -Authentication kerberos
$Session = New-PSSession -ComputerName $SCOMServer -Credential $Credential
$Session = get-pssession
Invoke-Command -Session $Session -ScriptBlock {
param($ComputerName, $endTime, $DeleteMM)
Import-Module OperationsManager
try {
$MonitoringObjects = Get-SCOMMonitoringObject | where {$_.DisplayName -like "$ComputerName*"}
$MObject.ViewName
catch {
Write-Host "Fehler beim Verbinden mit dem SCOM ist aufgetreten!`nBitte versuchen Sie es später noch ein Mal."
Write-Host "Vollständige Fehlermeldung: "$_.Exception.Message
if ($MonitoringObjects -eq $null) {
Write-Host "Servername konnte nicht gefunden werden: " $ComputerName
else {
foreach ($ComputerInstance in $MonitoringObjects) {
if ($ComputerInstance.InMaintenanceMode) {
if ($DeleteMM) {
#Wartung muss gelöscht werden
$ComputerInstance.StopMaintenanceMode([DateTime]::Now.ToUniversalTime(), "Recursive")
$Ausgabe = "Server aus dem Wartungsmodus entfernt."
else {
#Server ist Bereits im Wartungsmodus
$MMEntry = Get-SCOMMaintenanceMode -Instance $ComputerInstance
Set-SCOMMaintenanceMode -MaintenanceModeEntry $MMEntry -EndTime $EndTime -Comment "Wartungsmodus wird angepasst."
$Ausgabe = "Wartungsmodus für den Server " + $ComputerName + " ist angepasst bis " + ((Get-SCOMMaintenanceMode -Instance $ComputerInstance).ScheduledEndTime).ToLocalTime()
else {
if ($DeleteMM) {
#Server war nicht im Wartungsmodus und soll gelöscht werden
$Ausgabe = "Server war nicht im Wartungsmodus!"
else {
#Setzen des Servers in die Wartung
Start-SCOMMaintenanceMode -Instance $ComputerInstance -EndTime $endTime -Reason "PlannedOther" -Comment "Wartungsmodus wird gesetzt."
$Ausgabe = "Wartungsmodus für den Server " + $ComputerName + " ist gesetzt bis " + ((Get-SCOMMaintenanceMode -Instance $ComputerInstance).ScheduledEndTime).ToLocalTime()
#Ausgabe für die letzte Instanz:
Write-Host $Ausgabe
} -ArgumentList $ComputerName, $endTime, $DeleteMM
#Schliesse die Remote-Session
Remove-PSSession -Session $Session
#MAIN:
#Prüfung, ob die Parameter eingeben wurden:
if ($ComputerName -eq '') {
$ComputerName = Read-Host "Bitte den Servernamen eingeben"
$Dauer = Read-Host "Bitte die Dauer in Minuten eingeben (0 = Löschen des Wartungsfensters)"
#Wenn noch immer nichts gesetzt ist, dann abgebrochen:
if ($ComputerName -eq '' -OR $Dauer -eq '') {
Write-Host "Vorgang abgebrochen!"
else {
SetMaintenanceMode
Sleep 5
Regards.

Hi also in this post :)
Thats a nice query - thank you. But the systems with the error are not listed.
Maybe there is an error in our script:
foreach ($ComputerInstance in $MonitoringObjects) {
if ($ComputerInstance.InMaintenanceMode) {....$MMEntry = Get-SCOMMaintenanceMode -Instance $ComputerInstance

Similar Messages

  • I can't get my iMac to accept a CD/DVD disc.  It acts like there's already one in there but there isn't.  Tried the help menu but nothing worked.Suggestions?

    I can't get my iMac to accept a CD/DVD disc.  It acts like there's already one in there but there isn't.  Tried the help menu but nothing worked.Suggestions?

    Thank you, Allen.  My iMac is a 2009.  I can't shine a light into the disc drive slot as it has a built in whisker cover that prevents anything from getting in.  It will accept a disc half way in before the disc reaches a springy obstruction.
    About 3 weeks ago, the computer locked up so I inserted the OS disc and reinstalled it.  In general, the computer works just like it used to but we've had a few quirks appear; for example, this is one of them.  Also, we can't figure out how to keep from having to sign-in when we turn the computer on.  Also, we can't access our one on-line account anymore.  Very strange.
    Dave
    P.S.:  Just realized I mis-spelled your name.  Sorry Allan.
    Message was edited by: DTabbert

  • How to place multiple servers in Maintenance Mode in SCOM 2012

    Hi All,
    I am trying to place multiple servers in Maintenance Mode in SCOM 2012 but i could not find any PoSh script or any other solution to do it.
    Could someone help me please?
    Regards, Srini

    Hi,
    Please find the script.
    need to have access and you can provide list of servers in text file.
     param([int32]$TimeMin, [string]$Reason, [string]$Comment)
                    $api = new-object -comObject 'MOM.ScriptAPI'
                    Import-Module operationsmanager
                    New-SCOMManagementGroupConnection
                    $Servers = Get-Content "ServerList.txt"
                    $Time = (Get-Date).Addminutes($TimeMin)
                    Foreach ($Server in $Servers)
                                    #Get Computer instance
                                    $ComputerClass = Get-SCOMClass -Name Microsoft.Windows.Computer
                                    $ComputerClassInstance = Get-SCOMClassInstance  -Class $ComputerClass | Where {$_.DisplayName -eq $Server}
                                    If ($ComputerClassInstance.InMaintenanceMode -eq $true)
                                    #Write-Host $Server " is in maintenance mode"
                                    Write-Host $Server" already under Maintenance Mode or not accessible by SCOM, skipped from script execution" -foregroundcolor "red"
                                    $api.LogScriptEvent('MaintenanceModeScript.ps1', 201, 1, "$Server already found under MM, skipped from script execution")
                                    Else
                                    #Write-Host $Server " is NOT in maintenance mode, attempting to put in MM......."
                                    If ($ComputerClassInstance -ne $Null)
                                                    $HealthServiceWatcherClass = Get-SCOMClass -name:Microsoft.SystemCenter.HealthServiceWatcher
                                                    #Get Health Service Watcher Class instance of the server
                                                    $HSWClass = Get-SCOMClass -Name Microsoft.SystemCenter.HealthServiceWatcher
                                                    $HSWClassIns = Get-SCOMClassInstance  -Class $HSWClass | Where {$_.DisplayName -eq $Server}
                                                    #Starting the maintenance mode
                                                    Start-SCOMMaintenanceMode -Instance $HSWClassIns -EndTime $Time -Reason $Reason -Comment
    $Comment
                                                    Start-SCOMMaintenanceMode -Instance $ComputerClassInstance -EndTime $Time  -Reason $Reason
    -Comment $Comment
                                                    Write-Host "Health Service Watcher and Agent server "$Server " kept in maintenance
    mode for $TimeMin minutes"  -foregroundcolor "green"
                                                    $api.LogScriptEvent('MaintenanceModeScript.ps1', 200, 0, "$Server kept in maintenance
    mode for $TimeMin minutes")
                                    Else
                                                    Write-Host $Server" not found in Domain" -foregroundcolor "red"
                                                    $api.LogScriptEvent('MaintenanceModeScript.ps1', 202, 1, "$Server not found in domain")
    Regards
    sridhar v

  • Failed to get Monitor - Start Maintenance Mode

    Hi,
    Am struggling with a problem with Orchestrator R2 apparently not recognising output from a Monitor alert step in a run book.  I have Orchestrator 2012R2 and SCOM 2012R2 configured.  Orchestrator is co-located with VMM2012R2.
    Operating system for all is Windows server 2012
    I have installed and deployed the Orchestrator R2 Integration packs which in deployment manager state version 7.2
    I have checked to ensure that both Orchestrator, SCOM and VMM are all R2 (They are)
    I am looking to create a runbook that will start services as per the link here: (Thanks to Jakob for this)
    http://blog.coretech.dk/jgs/sco-2012-scom-2012-best-practice-monitor-alert-and-restart-a-service/
    I can test the connection to the SCOM server - fine
    I create the monitor alert step and test - fine
    I create the start maintenance mode step and get the following error:
    Filed to get Monitor.  The exception was "An object of class MonitoringObject with ID 00000000-0000-0000-0000-000000000000 was not found.".
    I have used the runbook tester and the monitoringobjectfullname is present in the output for the start maintenance mode step.
    However irrespective of the variable that I attempt to use in start maintenance mode step I continue to get the same error as above.
    The monitor alert step completes with no issues, but everytime on the start maint mode step it fails.
    I have validated the SCOM connection account has all the appropriate SCOM permissions.  I have also provided it with full domain admin rights, but with no success. 
    Any ideas on how to troubleshoot this would be welcomed
    Thanks in advance

    Hi Stefan,
    A little extension of your approach as this is only usable if you want to set a Windows Server into Maintenance Mode - but not e.g. for Distributed Apps
    I just required the "Start Maintenance Mode" Activity to set a distributed app and a websphere application server instance (which is not linked with the server itself). And I did not find any documentation how to fill the field - only for Windows
    Computer.
    So I'll post my result on how to get the value which needs to be entered within the "Monitor" field:
    (PowerShell - Use "Activities > System > Run .Net Script > Type: Powershell)
    Import-Module OperationsManager
    $object= Get-SCOMMonitoringObject -displayname "<desired object displayname";
    # or use the ID instead:
    # $object = Get-SCOMMonitoringObject -ID "<ID of object>";
    $name = $object.displayname;
    $fullname = $object.fullname;
    $monitor = $name + " : " + $fullname
    Then put $monitor within "published data" and you can use it directly in the "Start Maintenance Mode" Activity.
    This only works if the runbook is running on a SCOM management server as it requires the SCOM Powershell Module. But at least it somehow shows the syntax.
    Best Regards
    Klaus
    Austria

  • Cairo-dock starts in "maintenance mode"

    Hi,
    I've recently upgraded the cairo-dock, but since then it starts along with the <maintenance mode window>... When I try to close it, it reappears until the wifi connection settles down. I suspect that weather-dock is making troubles when it does not have connection to the internet.
    I've looked through the cairo-dock options, and it has an option to force maintenance mode, but it does not have one to force disabling it unfortunately.
    Anyone has any idea how to get rid of this?

    probably an issue with your configuration. had this once, deleted my .config/cairo-doc ( at least i think thats where it was) folder and it worked again - with default settings.

  • How to schedule Maintenance Mode in SCOM 2012?

    Hi
    How do I schedule Maintenance Mode in SCOM 2012? Do we have any tool for 2012 like we had with 2007?
    Regards,
    Akhilesh
    Thanks, Akhilesh

    Yep - to add a calendar takes some extra steps:
    E.g. 
    1) Create a database which includes a table to store information such as:
    - target for maintenance mode
    - scheduled time for maintenance mode
    - Comments
    - Duration
    - Reason
    2) The Service Request fires off an Orchestrator runbook that stores this information in the database
    3) Another Runbook that runs frequently that checks the database to see if it should kick off maintenance mode.
    It isn't any easy solution for maintenance mode. It works better for more simplistic scheduling e.g. we do implement this kind of logic for environment refreshes and backups where we use the SM Portal and Orchestrator to log a date and then have another
    runbook that runs at 2am every day to check if it should execute a backup \ refresh.  
    Cheers
    Graham
    Regards Graham New System Center 2012 Blog! -
    http://www.systemcentersolutions.co.uk
    View OpsMgr tips and tricks at
    http://systemcentersolutions.wordpress.com/

  • Looking for a Powershell Script which can put the scom servers in maintenance mode

    Looking for a Powershell Script which can put the scom servers in maintenance mode so that SCOM should not send an alert during planned task.
    Rahul

    1. Provide list of servers line-by-line in C:\ServerList.txt, make sure you provide limited no. of servers, do not exceed 20 - 25 per batch
    2. Save the script with suitable name (test.ps1)
    3. Open PowerShell cmd prompt
    4. Script accepts 3 params - TimeInMinutes, Reason and Comment
    **** Please note, this script will work for SCOM 2012 R2
    param([int32]$TimeMin, [string]$Reason, [string]$Comment)
    try
    $api = new-object -comObject 'MOM.ScriptAPI'
    Import-Module operationsmanager
    New-SCOMManagementGroupConnection
    $Servers = Get-Content "C:\ServerList.txt"
    $Time = (Get-Date).Addminutes($TimeMin)
    Foreach ($Server in $Servers)
    #Get Computer instance
    $ComputerClass = Get-SCOMClass -Name Microsoft.Windows.Computer
    $ComputerClassInstance = Get-SCOMClassInstance  -Class $ComputerClass | Where {$_.DisplayName -eq $Server}
    If ($ComputerClassInstance -ne $Null)
    $HealthServiceWatcherClass = Get-SCOMClass -name:Microsoft.SystemCenter.HealthServiceWatcher
    #Get Health Service Watcher Class instance of the server
    $HSWClass = Get-SCOMClass -Name Microsoft.SystemCenter.HealthServiceWatcher
    $HSWClassIns = Get-SCOMClassInstance  -Class $HSWClass | Where {$_.DisplayName -eq $Server}
    #Starting the maintenance mode
    Start-SCOMMaintenanceMode -Instance $HSWClassIns -EndTime $Time -Reason $Reason -Comment $Comment
    Start-SCOMMaintenanceMode -Instance $ComputerClassInstance -EndTime $Time  -Reason $Reason -Comment $Comment
    Write-Host "Health Service Watcher and Agent server "$Server " kept in maintenance mode"  -foregroundcolor "green"
    $api.LogScriptEvent('MaintenanceModeScript.ps1', 200, 0, "$Server kept in maintenance mode for $TimeMin minutes")
    Else
    Write-Host $Server" not found " -foregroundcolor "red"
    $api.LogScriptEvent('MaintenanceModeScript.ps1', 201, 1, "$Server could not be found in domain")
    Catch [system.exception]
    $api.LogScriptEvent('MaintenanceModeScript.ps1', 201, 1, $_.Exception.Message)
    Faizan

  • Flex/AS3 Best way to construct a derived class instance from an existing base class instance?

    What is the best way to handle the instantiation of a derived class from an existing base class.
    I have a base class which is being created via remote_object [RemoteClass alias] from the server.   I have other specialized classes that are derived from this baseclass, but serialization with the server always happens with the base class.     The base class has meta data that defines what the derived class is, for example
    [RemoteClass (alias="com.myco...')]
    public Class Base
         public var derivedType:String;
         public function Base()
    public Class Derived extends Base
         public "some other data"
         public function Derived()
    In my Cairgorm command which retrieves this object from ther server I want to do this:
    public function result (event: Object):void
        var baseInstance:Base = event.result;
         if (baseInstance.derivedType = "derived")
              var derivedInstance:Derived = new Derived( baseInstance );
    What is the most efficient way of doing this?   It appears to me that doing a deep-copy/clone and instantiation of the derived class is pretty inefficient as far as memory allocation and data movement via the copy.

    Thanks for the assistance.  Let me try to clarify.
    MY UI requires a number of composite classes.    The individual components of the composite classes are being transfered to/from the server at different times depending upone which component has changed state.    The construction of the composite classes from the base class happens in my clients business logic.
    Composition happens in a derived class; but server syncronization happens using the base class.    When I recieve the object from Blazeds through the remote object event, it is in the form of the base class.  I then need to instantiate the derived class and copy the elements of the base class into it (for later composite construction).   And likewise when sending the base class back to the server, I need to upcast the derived class to its base class.   But in this case just a mere upcast does not work.  I actually need to create a new base class and copy the attrbutes into it.  I believe this is limitation of how remoting works on Flex/AS3.
    My question is, what is the best way to turn my base class into it's derived class so further composite construction can take place.   The way I am currently doing it is to create a  load method on the base class, that takes the base class as on argument.  The load function, copies all of the instance attribute references from the base class to the target class.
    public Class Base
         public function Base()
         public function load(fromClass:Base)
        {  //  copy the references for all of the instance attributes from the fromClass to this class }
    Then,  after I recieve the base class from the server.   I create a new derived class and pass the base class into the load function like this:
                for (var i:int=0; i < event.result.length; i++) {
                    var derived:Derived = new Derived();
                    derived.load(event.result[i]);
    The drawbacks of this approach is that it now requires 2 extra instance creations per object serialization.   One on recieving the object from the server and one sending it to the server.    I assume copying references are pretty efficient.  But, there is probably some GC issues.     The worst of it is in code maintenance.   The load function now has to be manually maintained and kept in sync with the server class.
    It would be interesting to hear how others have solved this problem.      The server side is an existing application with around 2M LOC, so changing the code on the server is a non-starter.
    Thanks for your help.

  • OM2012 – Putting a Monitor in maintenance mode

    Hi there,
    I need to write a powershell script to put a Monitor in Maintenance mode. This is easily doable manually on the console whenever an alert comes up by putting the alert in Maintenance Mode.
    So far I managed to make my script to put the class of the Monitor into maintenance, as per bellow
    i.e. if the monitor is “Total CPU Utilization Percentage”, it would put  Microsoft Windows Server 2012 R2 Datacenter in maintenance mode for the computer $ComputerName.
    $ComputerName = Read-Host “Enter computer name”
    $MonitorName = “Total CPU Utilization Percentage”
    $Monitors=Get-SCOMMonitor -ComputerName $strComputerName | where {$_.DisplayName -eq $MonitorName}
    $Time = ((Get-Date).AddMinutes(6))
    foreach ($Monitor in $Monitors) {
    $Instance = Get-SCOMclass -name $Monitor.target.identifier.path | Get-SCOMClassInstance #| where {$_.Path -eq $ComputerName}
    Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment: “Server maintenance”
    I can’t figure our how to simply put “Total CPU Utilization Percentage” (or any other Monitor) in maintenance mode
    Thanks for your help !

    Yes, use the "Start Maintenance Mode" Activtiy of the Integration Pack for OpsMgr.
    www.sc-orchestrator.eu ,
    Blog sc-orchestrator.eu

  • All services stuck in maintenance mode

    I've got a problem on Solaris 10. All of the enabled inet services are in maintenance mode. rlogin, ftp, telnet, stlisten, xfs, etc, etc - are all in maintenance mode. The inetadm command shows no online services, only disabled and maintenance. I've tried clearing them with svcadm but they won't clear. It won't show any explanation for why.
    What could be wrong to cause this?
    Thanks for any suggestions.
    Randy

    Thanks very much for the very helpful suggestions. svcs -xv does not show anything helpful - for the Reason, simply "Restarter gave no explanation". The svc:/network/inetd:default is indeed enabled and healthy.
    /var/adm/messages, however, has information that might point to the problem. Regrettably, I don't understand the message and am hoping someone here can enlighten me. For each of the services that is in maintenance mode, these messages appear:
    Nov 3 17:59:44 trsun006 inetd[322]: [ID 702911 daemon.error] Property exec for method inetd_start of instance svc:/network/login:rlogin is invalid
    Nov 3 17:59:44 trsun006 inetd[322]: [ID 702911 daemon.error] Invalid configuration for instance svc:/network/login:rlogin, placing in maintenance
    I don't understand what it means by "Property exec for method inetd_start ... is invalid".
    I issued these commands-
    [trsun006 27] sbin > inetadm -l rlogin | grep exec
    exec="/usr/sbin/in.rlogind"
    [trsun006 28] sbin > ls -l /usr/sbin/in.rlogind
    -r-xr-xr-x 1 root bin 36372 Jan 22 2005 /usr/sbin/in.rlogind*
    How can I debug this problem?
    Randy

  • Maintenance Mode never ends

    I want to put a scom gruop into Maintenance. The Management Server is not member of it.
    When I use the following Powershell Script with SCOM 2012....
    Import-Module OperationsManager
    $Instance = Get-SCOMGroup -displayname "<Group>"
    $Time = ((Get-Date).AddMinutes(90))
    Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "Automatic WSUS Updates" -Reason "PlannedOperatingSystemReconfiguration"
    ....the Maintenance mode never ends. I have to stop the mode manually. When I use the SCOM Console everything is fine.

    In my environment, it works but may be in some delay. Moreover, you can use get-scommaintenancemode to watch whether the maintenace mode and schedule end time is correct.
    You may be refer to Pete Zerge blog "r OpsMgr 2012: Group Maintenance Mode via PowerShell"
    http://www.systemcentercentral.com/opsmgr-2012-group-maintenance-mode-via-powershell-the-way-it-should-be/
    Roger

  • SCOM 2012 Maintenance Mode PowerShell Script Problems

    I've seen other questions about this topic before, but none of them seem to address my specific problem, so I am starting a new thread.
    I am writing a script to put a single server (not a group) into maintenance mode.   Here is the command that it ultimately tries to call:
     Start-SCOMMaintenanceMode-Instance$Instance-EndTime$EndTime-Reason$Reason-Comment$Comment     
    So an exmaple would look like this:
    Start-SCOMMaintenanceMode -Instance "$Instance -EndTime "02/03/2014 15:26:00" -Reason "PlannedOther" -Comment "Testing Maintenance Mode"
    When my script tries to run this command, this is the error message that I get:
    Start-SCOMMaintenanceMode : Start time must be before end time for maintenance mode.
    Parameter name: startTime
    At C:\users\x036036\Desktop\Start-SCOMMaintenanceModeForServer.ps1:143 char:21
    +                     Start-SCOMMaintenanceMode -Instance $Instance -EndTime $EndT ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (Microsoft.Syste...anceModeCommand:StartSCMaintenanceModeCommand) [Start-SCOMMaintenance
       Mode], ArgumentOutOfRangeException
        + FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.OperationsManagerV10.Commands.StartSCMaintenanceModeCommand
    I've tried to look at Start-SCOMMaintenanceMode help online, but I don't see that "startTime" is a parameter.  So what is this error message talking about?  What am I missing?  

    Thanks for your help.   I didn't see your response until just now, but I have been playing around with this all since my last response.   I got it to work.  I wish I could pinpoint what exactly I changed to get it to work, but I
    feel like I've been changing so much stuff that I'm not sure any more.
    Just in case anyone finds it useful, here is the code.
    [CmdletBinding(SupportsShouldProcess=$true)]
    param
    [Parameter(Mandatory=$True,
    ValueFromPipeline=$True,
    ValueFromPipelineByPropertyName=$True,
    HelpMessage='What is the server you want to put in Maintenance Mode?')]
    [Alias("Server")]
    [string[]]$ServerName,
    [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. Format is 1/29/2014 8:59:26 AM')]
    [Datetime]$end,
    [Parameter(Mandatory=$False,
    ValueFromPipeline=$True,
    ValueFromPipelineByPropertyName=$True,
    HelpMessage='PlannedOther, 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 ServerName $ServerName in Maintenance Mode"
    Function Start-SCOMMaintenanceModeForServer
    [CmdletBinding(SupportsShouldProcess=$true)]
    param
    [Parameter(Mandatory=$True,
    ValueFromPipeline=$True,
    ValueFromPipelineByPropertyName=$True,
    HelpMessage='What is the server you want to put in Maintenance Mode?')]
    [Alias("Server")]
    [string[]]$ServerName,
    [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. Format is 1/29/2014 8:59:26 AM')]
    [Datetime]$end,
    [Parameter(Mandatory=$False,
    ValueFromPipeline=$True,
    ValueFromPipelineByPropertyName=$True,
    HelpMessage='PlannedOther, 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-SCOMMaintenanceModeForServer"
    #Check for minumum Maintenance mode period of 5 mins.
    $start = Get-Date
    $5MinFromNowTime = $start.AddMinutes(5)
    #$end = [datetime]$end
    $end = $end.AddSeconds(5)
    if($end -lt $5MinFromNowTime)
    Write-Error "The time span for the maintenance mode should be at least 5 minutes." -ErrorAction Stop
    Write-Verbose "Following server will be put in Maintenance Mode: $ServerName"
    $MSs = Get-SCOMManagementServer
    } #End Begin
    Process
    Write-Verbose "Checking if server $ServerName is a Management Server"
    #Write-Verbose ($MSs | Select DisplayName)
    if(($MSs | Select DisplayName) -eq $ServerName)
    Write-Verbose "We don't want to put a Management Server in Maintenance Mode. Skipping"
    else
    Write-Verbose "Let's put server $ServerName in Maintenance Mode"
    $Instance = Get-SCOMClassInstance -Name $ServerName
    if ($PSCmdlet.ShouldProcess("Putting $ServerName in Maintenance Mode until $($end).") )
    Write-Verbose ("Start-SCOMMaintenanceMode -Instance " + $Instance + " -EndTime " + $end + " -Reason " + $Reason + " -Comment " + $Comment)
    Start-SCOMMaintenanceMode -Instance $Instance -end $end -Reason $Reason -Comment $Comment
    }#End of whatif
    }#End of else
    if ($PSBoundParameters['EventLog'])
    write-eventlog -LogName "Operations Manager" -Source "OpsMgr SDK Service" -EventID 999 -message "The following Objects are put into in Maintenance Mode until $($end) : $($ServerName)"
    }#End if
    } #End Process
    End
    Write-Verbose "Finished Function Start-SCOMMaintenanceModeForServer 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-SCOMMaintenanceModeForServer -ServerName $ServerName -end $end -Reason $Reason -Comment $Comment -EventLog
    else
    Start-SCOMMaintenanceModeForServer -ServerName $ServerName -end $end -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)"
    There is one remaining problem with this script.   It does not correctly check to see if something is a management server. We have two management servers. These are the applicable lines, which I still haven't gotten to work yet. First, this retrieves
    the list of my Management servers:
    $MSs=Get-SCOMManagementServer     
    Next, these lines are supposed to check if the server I specified is a management server:
    if(($MSs | Select DisplayName) -eq $ServerName)
    Write-Verbose "We don't want to put a Management Server in Maintenance Mode. Skipping"
    Thanks to the Intellisense pop-up deal, I can see that $MSs does get my two management servers. And I can clearly see that there is a DisplayName column. And I can also see that the $ServerName does match what I put in my command line.   But it doesn't
    seem to catch them if they are actually equal to each other. I don't know if it's because there's two Management Servers, and it doesn't know how to compare like that? Any idea? Is there some sort of loop I need to write so that it compares is to the DisplayName
    for EACH Management Server it finds? Any help would be greatly appreciated.

  • Another SCOM Maintenance Mode query/advice...

    Hi,
    Just looking some advice on setting SCOM Maintenance Mode (using SCOM/SCO 2012R2)...
    I want to be able to set a server entirely into MaintMode, ie similar to choosing "Selected object AND ALL their contained objects" from SCOM console.
    I had asked similar question back in SCOM 2007/Opalis days, but the solution then (placing server and health server watchers separately into maintenance as per Anders blog http://contoso.se/blog/?p=2164 I'm not sure is appropriate now as I believe MaintMode
    is handled differently in 2012.
    I have seen some pretty complex solutions where using custom built DBs to hold MaintMode status etc.  Was hoping theres a neater/simpler soultion using the Orchestrator Activities these days.
    If not possible using Native Orchestrator then the fallback would be to try use powershell commandlet.  Looking at the Commandlet Examples if I used the following example solution, will that effectively put the server object (and all contained objects
    into maintenance which is what I'm trying to achieve.
    Windows PowerShell
    PS C:\> $Instance = Get-SCOMClassInstance -Name "Server01.Contoso.com"
    PS C:\> $Time = ((Get-Date).AddMinutes(10))
    PS C:\> Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "Applyin
    Any advice to this recurring pain point of SCOM much appreciated.
    PS. Not sure if this post is better placed here or in SCOM/Powershell forum so can move if necessary...

    Hi Michael,
    thanks for your reply confirming the powershell command will work.
    I have actually just tried using the native Start Maintenance Mode Activity which actually seems to do as required - if the monitor selected is the relevant <servername> : Microsoft.Windows.Computer: <servername> object then it seems to put the
    entire server into maintenance.  I tested against a server which happened to also host SQL role, so when I placed in Maint via the runbook  I then stopped the SQL service and no alerts generated from SQL MP and I could see the spanner Icon against
    the server in relevant SQL node views aswell.
    I had though maybe that only windows MP stuff might be supressed - so again when I came across all the very complex solutions to apply Maint mode properly I wasnt sure if it was still relevant in 2012 (even though some of those solutions indicated for use
    on SCOM/SCO 2012?)
    Anyway if the simple solution work - as it appears to do so, then I'll run with that - unless someone can tell me why not?...
    Cheers

  • Get class Instance, and then get hers attributes

    Hi Gurus,
    i'm new to ABAP Object,
    creating an a BSP whit MVC controller i've try to implement the class controller,
    but on a method of it i want to get instance of the class parents:
    the class that i implement is an extension of CL_BSP_CONTROLLER2.
    In this class in the method DO_REQUEST ( for example ) i try to get the instance of the class
    parent ( and i got it! ) using this syntax:
      data: Parent type ref to IF_BSP_DISPATCHER,   " type take from attribute M_PARENT of the class
    Parent = ME->M_PARENT.
    In debug i see that 'Parent'  get rightly the class parent instance but than i want do this:
    (i want get the sub controller of the main contoller 'parent', in debug i can see everything fine)
       SubController = Parent->GET_ATTRIBUTE(LEFT_CONTROLLER).
    But the compiler say that the class instance 'Parent' has no methods and no attribute.
    i've try other syntax like:
        call METHOD Parent_>GET_ATTRIBUTE
            IMPORTING
         LEFT_CONTROLLER)
      call METHOD ME->M_PARENT->GET_CONTROLLER
       EXPORTING
         CONTROLLER_ID = 'search'
       IMPORTING
         CONTROLLER_INSTANCE = Parent2
    No one work!
    How can i do?
    Here screnshot of that i see in debug mode, and that i want get:
    http://img190.imageshack.us/i/1debugscreen.jpg/
    http://img10.imageshack.us/i/2debugscreen.jpg/
    Thanks in advance,
    Davide

    Hi Pawan,
    classes ref to CL_BSP_CONTROLLER2 like my controller class, have an attribute
    M_PARENT type IF_BSP_DISPATCHER.
    If the class is a subclass of an main class it has the M_PARENT attribute containing the instance of the parent class,
    i can see in debug mode ( here example: http://img40.imageshack.us/img40/1648/3debugscreen.jpg )
    i can get this attribute:
      data: Parent type ref to IF_BSP_DISPATCHER,   " type take from attribute M_PARENT of the class
    Parent = ME->M_PARENT.
    but  the interface IF_BSP_DISPATCHER has no attribute and no method defined, and if i declare 'Parent' as type ref to
    CL_BSP_CONTROLLER2 the compiler return error
          <=>      "The type of "PARENT" cannot be converted to the type of "ME->M_PARENT". "
    Davide

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

    I am still 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:
    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 isn't fully working, is intended 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:
    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!

    Hello, thanks for your response.  Unfortunately, it does not appear that the link you provided works.
    As far as not including "selected objects and all their contained objects" I am wondering if there is a way for me to tell for sure. One thing I found was that if I run this script and put the server into maintenance mode, then I go into
    SCOM and click on Edit Maintenance Mode for that server, it shows me the details.   It has some comment, and my selected reason, based on the code I posted above.   It also DOES have "selected objects and all their contained objects"
    selected at top.  So it seems to me like it is working correctly, and does contain all the objects.   If you think that 'Edit' screen would be inaccurate for some reason, please let me know.  Or if you know of a way for me to check and
    confirm, please let me know that as well.
    As for REMOVING it from maintenance mode, I did eventually find a line of code that I think works.  Here's what my code looks like now:
    Import-Module OperationsManager
    $Instance = Get-SCOMClassInstance -Name $FQDN
    If ($Instance)
    $MMEntry = Get-SCOMMaintenanceMode -Instance $Instance If ($MMentry)
    $Instance.StopMaintenanceMode([DateTime]::Now.ToUniversalTime(),[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive);
    When I use the above code to STOP maintenance mode, the green checkmark does reappear for the server, and everything seems to be being monitored again.   Unlike before, where the maintenance mode icon would go away, but it would never change back
    to saying 'Monitored' again.  So I think that changing that one line to stop maintenance mode seems to have done the trick.
    So I guess my last concern now is just putting in maintenance mode initially, as I was talking about above.  If you still think the 'Edit Maintenance Mode' screen is not a good indicator of what my code does, please let me know.

Maybe you are looking for

  • Trasnform current date to format MM/dd/yyyy HH:mm:ss AM/PM

    Hi All, How do I transform current date to format MM/dd/yyyy HH:mm:ss AM/PM? I am able to get the format MM/dd/yyyy HH:mm:ss by using the standard date function. How do I get AM or PM to end of MM/dd/yyyy HH:mm:ss?? Thanx Navin

  • I bought a new song and the song won't play in itunes

    here's the thing: I'm trying to desperately finish my homework and I need to download a song so the teacher can play it in class. So all the songs on my nano aren't good. Don't get me wrong, I'm not new and I love iTunes! The problem is is that I bou

  • Backspace, enter and space shortcuts don't work.

    Backspace doesn't work for back; space doesn't work for page down; return doesn't work for SnapBack. I've no idea what caused this problem.

  • Problems activating signal express 2.0 in labview

    Hello, I have purchased a copy of LabVIEW Base Edition 8.2.1 and Signal Express 2.0.  I receive the following error when I create a LabVIEW VI containing a Signal Express VI (in this case a Signal Express Create Signal VI): NI_MAPro.lvib: This librar

  • "Must Restart Computer?"

    Last night I was on my iBook G4. Suddenly, a transparent grey box appeared and in 4 or 5 different languages (freezes up the whole system), it said that I must restart the computer by holding down the power button for a few seconds. I did that. When