Maxim's profileOpsMgr 2007 NotesBlogLists Tools Help

Blog


    February 20

    Get a list of all computers in Maintenance Mode (powershell)

    Want to know which of your managed computers are currently in Maintenance mode? The fastest and probably easiest approach is to use a tiny powershell script provided below.

    $rootMS="rms01.contoso.com"

    #Setting up a connection to management group

    add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;
    set-location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
    new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;
    set-location $rootMS -ErrorVariable errSnapin;

    #Retrieving objects that are in Maintenance Mode
    #We're getting here all objects of Windows Computer class

    $computerClass = get-monitoringclass -name:Microsoft.Windows.Computer
    $ComputersInMaintenance = get-monitoringobject -monitoringclass:$computerClass -criteria:"InMaintenanceMode=1"
    foreach ($computer in $computersInMaintenance){
    Write-Host $computer.displayname
    }

    Notice two things. First, in order to connect to the management group, the user executing powershell script should have enough privileges to perform this operation. Otherwise you’ll get an error. So if you want this script (or any other script that connects to OpsMgr management group) to be executed in a context of user that is not a member of any of OpsMgr User Roles, you should add –Credential parameter when calling new-managementGroupConnection cmdlet. Like this

    new-managementGroupConnection -ConnectionString:$rootMS –Credential (Get-Credential) -ErrorVariable errSnapin;

    Then you will be prompted to enter appropriate user’s credentials.

    get-credential

    After providing correct logon information a connection to the management group will be successfully initiated.

    The second thing is about classes of managed objects we’re retrieving in the script above. As you might already noticed, we declare $computerClass variable and bind it with Microsoft.Windows.Computer class. This means that we will get only Windows Computer object that are currently in Maintenance mode. Certainly you may use any class you want instead of Windows.Computer. For example, if you want to determine Health Service Watcher objects that are now in MM, apparently you will use Microsoft.SystemCenter.HealthServiceWatcher class:

    $computerClass = get-monitoringclass –name:Microsoft.SystemCenter.HealthServiceWatcher

    For your convenience, there is one more tip that will probably help you with names of different classes. If you want to know, let’s say, a full name of SQL DB Engine class, you may call the Get-MonitoringClass cmdlet like i do here:

    get-monitoringclass | where {$_.Name -match "DBEngine"} "| ft name

    As result you will get something like this.

    Name
    ----
    Microsoft.SQLServer.DBEngine
    Microsoft.SQLServer.2005.DBEngine

    Now when you know the exact name of the class, you can easily use them in your script. As you guess, to determine SQL 2005 databases currently being in MM, you will use Microsoft.SQLServer.2005.DBEngine class.

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Trackbacks

    The trackback URL for this entry is:
    http://maxim-ua.spaces.live.com/blog/cns!9C26C04B756ADA31!149.trak
    Weblogs that reference this entry
    • None