Pulling all Enumerations and Child Nodes with PowerShell SCSM 2012 R2

I have been working with a colleague of mine Chris Jones on some reporting components for Service Manager and we wanted to pull all of the Enumerations within Service Manager and display them out.  We decided to use SMLets to do this to make it easier. This is the beginning of a data dictionary which will ultimately be saved to Excel or another office product format, but for now I wanted to share the standard PowerShell.

Below is the sample script.

Function Get-ChildEnumeration

       $var = $var + "`t"
       $comma = $comma + ","
        $parentenum = Get-SCSMEnumeration -Id $Enumeration

     $Query = $parentenum | Get-SCSMChildEnumeration -Depth OneLevel

           if($prevcount -ne $query.count)

     foreach($item in $Query)

     Write-Host $var $item.DisplayName
          $csv = $comma + $item.DisplayName
           add-content -path "c:\temp\stuff.csv" -Value $csv
  $prevcount = $query.count
      Get-ChildEnumeration -Enumeration $item.id


     $var ="`t"

function Get-RootEnumeration
foreach($root in (Get-SCSMEnumeration | ? {$_.Parent -eq $null} | ? {$_.DisplayName -ne $null}))
    Write-Host $root.DisplayName
        $csv = $root.DisplayName + $comma
  add-content -path "c:\temp\SCSMEnumerations.csv" -Value $csv
  Get-ChildEnumeration -Enumeration $root.id



Afterwards the script output will look similar to the screenshot below.  Hope this helps others out there looking for something similar.


Comments (11)

  1. Anonymous says:

    Alex, that is interesting it’s telling us that the Enumeration variable we passed to Get-Enumerations is blank. To test I might suggest throwing a line above it like Write-Host "***" $Enumeration "***" and lets see what the enumeration was before and after
    the error was thrown to determine why it was like that. Off the top of my head though not sure why you would be seeing this.

  2. Anonymous says:

    Guys, I had a little bit of free time this morning so added some simple csv addition, nothing fancy but puts it in a similar format as you see with the output.. let me know if this will tide you over until I can properly do it.

  3. Anonymous says:

    I will continue to always post more. I want to have the CSV part done by the end of the month, though quite busy. I will be sure to update this post when that is complete. Though Alex what do you mean by separating list rnums for other types? Which types
    are you talking about.

  4. Anonymous says:

    Great thinking Alex. I get what you mean now as some of the enumerations are silly ones not used in the console. I will look to separate those out and will add your addition here this week when I get the cycles to be able to do so.

  5. Alex says:

    Hi George, super work!
    Question – any reason why it would state:
    "Get-SCSMEnumeration : Cannot bind parameter ‘Id’ to the target. Exception setting "Id": "Object reference not set to an instance of an object." at line:8, char:42

  6. Alex says:

    Apologies George, I was running it locally (brain-freeze), not on the SCMS Console Server.
    Running it on the Server works as expected!
    How far are you progressing on exporting it (.csv)? I’m looking to separate the result into columns/cells…
    Anyways great work – way better than any other solutions I’ve seen recently.

  7. shoongana says:

    Much thanks to you such a great amount of for the exact useful article, extremely supportive to the general public and I trust you will continue presenting and following with respect to on this.

  8. Alex says:

    Ooh – and somehow separating List enums for other types of enums…

  9. Alex says:

    Thanks george, just to clarify I mean’t distinguishing ‘List’ lists (as in lists used on a workitem form), and other enum lists.

  10. Alex says:

    Hi George, I found a little trick for the script to ensure that the List items are displayed in Ordinal order (as they display in the console). Amending to this line:

    $Query = $parentenum | Get-SCSMChildEnumeration -Depth OneLevel | Sort-Object -Property Ordinal

  11. Alex says:

    George, I’m also working on exporting the List Value (DisplayName), Description and MP Name(GetManagementPack). I can get at them, but the descript and MP Name inherit the indentation. Ideally i’d want the Descipt and MP Name allocated to their own column/s.
    Incident Status
    Active [System.WorkItem.Incident.Library, 31bf3856ad364e35, 7.5.3079.0]
    Linked to Parent [System.WorkItem.Incident.Library, 31bf3856ad364e35, 7.5.3079.0]
    Updated Via E-Mail [ServiceManager.IncidentManagement.Configuration]