Wednesday, 15 September 2010

List current values for a list enumeration in Service Manager

Credit goes to Patrik for this forum post.

Create a powershell script containing the following:

-------------

function getChildren([Microsoft.EnterpriseManagement.Configuration.ManagementPackEnumeration]$parent)
{
$outPut = "$outPut - " + $parent.DisplayName
Write-host $outPut

Foreach ($child in Get-SCSMEnumeration?{$_.Parent -eq $parent})
{
getChildren $child
}
}

Import-module smlets
$rootEnumElementName = 'ChangeAreaEnum$'
$parent = Get-SCSMEnumeration -Name $rootEnumElementName -ComputerName Servername|?{$_.Parent -eq $enum}

getChildren $parent

----------------

Change the 'ChangeAreaEnum$' to reflect the root element of your custom lists internal name (you should leave the dollar sign on the end). Also change the ServerName in the script to match your SCSM server name.

To get this, run the following command in PowerShell:
Get-SCSMEnumeration|?{$_.DisplayName -eq 'Incident Classification'}

Change the 'Incident Classification' to the name of your list as shown in the Service Manager console.

3 comments:

Konstantin Slavin-Borovskij said...

Hey Steve,

Nice write-up, helped me solve a problem.

A small syntax error in your Foreach-loop: You're missing a pipe before the question mark.

Thanks again.

Anonymous said...

Good job and many thanks for your effort.

Now how can export the result in CSV file?

arman ramazyan said...

Here's what I created to export the results to csv. Its not the cleanest code but it works :)

import-module smlets #imports the smlets module to connect to SCSM
$rootEnumElementName = 'incidentclassificationenum$' #sets the classification to get the childs for
$parent = Get-SCSMEnumeration -Name $rootEnumElementName | ? {$_.Parent -eq $enum} #sets the parent as the root that we are going to search
$outItems = New-Object System.Collections.Generic.List[System.Object] #creats a list of objects that you can add to $outitems
$getparent = Get-SCSMEnumeration | ? {$_.Parent -eq $parent} #gets all of the parents in $parent
Foreach ($dad in $getparent) # for each dad in the parent list, add that parent to the $outitem list and then see if it has a child, add that child to that list right under
{
foreach ($item in $dad)
{
$outItems += $dad #adding the dad to the list
foreach($item in $dad)
{
$child = Get-SCSMEnumeration | ? {$_.Parent -eq $dad}
}
$outItems += $child #adding the child to the list
}
}
$outItems | export-csv C:\classifications.csv -NoTypeInformation -Force #export the list to c:\classifications.csv