Thursday, May 24, 2012

[OpsMgr 2007R2] Get member of all SCOM groups and export result in CSV files - Powershell script

Here is a script that will help you to create a CSV file per SCOM group. Each CSV file will have the name of the SCOM group and will contain this information
  • Name
  • Path
  • DisplayName
  • FullName
  • IsManaged
  • LastModified
  • HealthState
  • StateLastModified
  • IsAvailable
  • AvailabilityLastModified
  • InMaintenanceMode
  • MaintenanceModeLastModified
  • MonitoringClassIds
  • LeastDerivedNonAbstractMonitoringClassId
  • Id
  • ManagementGroup
  • ManagementGroupId
Empty group does not create a CSV file.

  1. function GetDisplayName($object){
  2.      $displayName = [System.String]::Empty
  3.      if(($object.DisplayName -eq $null) -or ($object.DisplayName.Length -eq 0)){
  4.            $displayName = $object.Name;
  5.      }
  6.      else {
  7.            $displayName = $object.DisplayName;
  8.      }
  9.      $displayName;
  10. }
  11. $mg = (Get-ManagementGroupConnection).ManagementGroup
  12. $groups = $mg.GetRootPartialMonitoringObjectGroups() | sort DisplayName
  13. foreach($group in $groups) {
  14.      Write-Host
  15.      Write-Host $group.DisplayName
  16.      $groupMembers = $group.GetRelatedPartialMonitoringObjects([Microsoft.EnterpriseManagement.Common.TraversalDepth]::OneLevel);
  17.      if($groupMembers.Count -eq 0) {
  18.            Write-Host "The group is empty"
  19.      }
  20.      else {
  21.             $groupMembers | Select-Object DisplayName,Path,@{name="Type";expression={foreach-object {GetDisplayName $_.GetLeastDerivedNonAbstractMonitoringClass()}}} | sort DisplayName | ft
  22.             $FileName = $group.DisplayName
  23.             $FileName += ".csv"
  24.             $OutPath = $FileName
  25.             $groupMembers | Export-Csv -Path $OutPath -NoTypeInformation
  26.      }
  27. Write-Host
  28. }

How to use it :
- First connect to you management group
  1. add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
  2. set-location "OperationsManagerMonitoring::";
  3. new-managementGroupConnection -ConnectionString:MyRMS.MyDomain -Credential (get-credential "Domain\Account");
 - secondly, set your location where you want to store the created CVS files :
  1. set-location c:\temp
- Then execute the script :



Result will be :
 And you will retrieve your files in the location you have set - in my case :



This posting is provided "AS IS" with no warranties.

No comments:

Post a Comment