Maxim's profileOpsMgr 2007 NotesBlogLists Tools Help

OpsMgr 2007 Notes

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.

February 10

Determine a computer’s group with Powershell

If your OpsMgr environment has a complex group structure with a huge amount of groups and subgroups, it’s going to be rather difficult to determine a group membership of the particular computer. Here is a small powershell script that allows you to find out a computer’s membership very quickly.

Usage is clear, just pass a computer FQDN as a parameter.

>C:\GetGroupsThatContainComputer.ps1 <computerFQDN>

like >C:\GetGroupsThatContainComputer.ps1 hydra.contoso.com

As result you will get a list of all groups that contain computer hydra.contoso.com

Here is full source code of GetGroupsThatContainComputer.ps1 file:

 

param($computerFQDN)

function GetGroupNames($computerFQDN)
{
$containmentRel = Get-RelationshipClass -name:'Microsoft.SystemCenter.InstanceGroupContainsEntities'

$computerClass = Get-MonitoringClass -name:"Microsoft.Windows.Computer"

$criteria = [string]::Format("PrincipalName = '{0}'",$computerFQDN)

$computer = Get-MonitoringObject -monitoringClass:$computerClass -criteria:$criteria

$relatedObjects = $computer.GetMonitoringRelationshipObjectsWhereTarget($containmentRel,[Microsoft.EnterpriseManagement.Configuration.DerivedClassTraversalDepth]::Recursive,[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive)

foreach($group in $relatedObjects)
{
$group.SourceMonitoringObject.DisplayName
}

}

GetGroupNames $computerFQDN

 

Enjoy!


This posting is provided AS IS with no warranties. Use it at your own risk.

August 20

First entry

Hi all,

I'm going to post here my notes and share my experience on System Center Operations Manager 2007. 

Hope, this blog will be interesting and you'll find some useful information. Cheers for now!

 
There are no categories in use.