Relationship properties
Hi Team,
I tried something for see the incident class properties with the below command and it is working fine.
$IC=get-scsmclass -name system.workitem.incident$
$IC.getproperties("recursive") --> This command retrieves almost all of the fields for the incident module with few columns as (Name, Key, Required, AutoIncrement, Type and DisplayName)
Similarly, I tried to get the "affecteduser" using Relationship class. I used the below commands. Unfortunately, it did not work.
$RC=get-scsmrelationshipclass -name system.workitemaffecteduser$
$RC.getproperties("recursive") --> This is not working
Could anyone please let me know what was wrong in the above command?
Appreciate your help!!!
Regards,
Jansi
Answers
I just wrote something similar to this. There may be an existing method, but I couldn't find it. So this is what I did:
$className = "system.workitem.incident$"
$wiClass = Get-SCSMClass -Name $className
$extensions = $wiClass.GetDerivedTypes()
$properties = New-Object System.Collections.ArrayList
$properties.AddRange($wiClass.getproperties())
foreach ($e in $extensions) {
$subClass = Get-SCSMClass -name $e.Name
$props = $subClass.getProperties()
$properties.AddRange($props)
}
$properties
I thought immediately after posting that this would be pretty useful wrapped as a function. So I quickly wrote one and did a quick test again using the incident class:
function Get-ClassProperties {
param(
[parameter(mandatory=$true)][string]$ClassName,
[parameter(mandatory=$false)][switch]$IncludeBaseClass
)
$properties = New-Object System.Collections.ArrayList
$ClassToGetPropsFor = Get-SCSMClass -Name $className
$extensions = $ClassToGetPropsFor.GetDerivedTypes()
if ($IncludeBaseClass) {
$baseTypes = $ClassToGetPropsFor.getBaseTypes()
foreach ($type in $baseTypes) {
$properties.AddRange($type.getproperties())
}
}
$properties.AddRange($ClassToGetPropsFor.getproperties())
foreach ($extension in $extensions) {
$subClass = Get-SCSMClass -name $extension.Name
$props = $subClass.getProperties()
$properties.AddRange($props)
}
return $properties
}
Get-ClassProperties -ClassName "System.Workitem.Incident$" -IncludeBaseClass