Home Self-Service Portal - Community
Options

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

  • Options
    Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭

    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

  • Options
    Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭

    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

Sign In or Register to comment.