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.
Comments
- Anonymous
January 01, 2003
The comment has been removed - Anonymous
January 01, 2003
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. - Anonymous
January 01, 2003
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. - Anonymous
January 01, 2003
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. - Anonymous
July 09, 2014
The comment has been removed - Anonymous
July 10, 2014
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. - Anonymous
July 10, 2014
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 - Anonymous
July 10, 2014
Ooh - and somehow separating List enums for other types of enums... - Anonymous
July 13, 2014
Thanks george, just to clarify I mean't distinguishing 'List' lists (as in lists used on a workitem form), and other enum lists. - Anonymous
July 13, 2014
The comment has been removed - Anonymous
July 13, 2014
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]