George Wallace's Blog

Posts in this blog are provided "AS IS" with no warranties, and confers no rights as specified in the Terms of Use

Pulling all Enumerations and Child Nodes with PowerShell SCSM 2012 R2

Pulling all Enumerations and Child Nodes with PowerShell SCSM 2012 R2

  • Comments 11
  • Likes

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
{
    Param(
        $Enumeration

        )
       $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
}

}

Get-RootEnumeration

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

PSOutput

Comments
  • 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

  • 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.

  • 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.

  • 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.
    http://socialformula.com/instagram/followers

  • Ooh - and somehow separating List enums for other types of enums...

  • 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.

  • 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.

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

  • 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

  • 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.

  • 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. see:
    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]

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment