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
{
    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