SCSM adding users to a particular CI class RRS feed

  • Question

  • Hello All

    I am trying to make a script which will add users to custom CI in SCSM . Here is my scenario . I have created a custom CI class called ABC . Now i need to add users into the Configuration Items: Computer Service and People section in Related Items tab. I can add the users from the console , and its works perfectly . But when i try to add the user from a PowerShell script it fails , it fails with the below error message saying that its not valid for insertion (but i can add users manually). Can someone please help me and point me in correct direction

    $id = '386cdeef-f1d5-4a73-90e0-3a80227d00d9'
    $test = Get-SCClassInstance -Class (Get-SCClass -Name "ABC") | Where-Object {$_.id -eq $id}
    $user = Get-SCClass -Name "Microsoft.AD.UserBase" | Get-SCSMObject  -Filter "DisplayName -eq 'PQR' "
    $relationship = Get-SCSMRelationshipClass -name System.WorkItemRelatesToConfigItem
    New-SCSMRelationshipObject -Relationship $relationship -Source $test -Target $user -Bulk

    Error message

    New-SCSMRelationshipObject : The object with ID bd8bb2f1-e109-0b8d-f252-d6280c7c9f36 is not of a valid class for insertion.

    At line:5 char:1

    + New-SCSMRelationshipObject -Relationship $relationship -Source $test -Target $us ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (Microsoft.Enter...ationshipObject:CreatableEnterp...ationshipObject) [New-SCSMRelationshipObjec

       t], ArgumentException

        + FullyQualifiedErrorId : SourceError,SMLets.NewSCSMRelationshipObject

    Wednesday, December 31, 2014 12:10 AM

All replies

  • Note the relationship you're attempting to use. "Work Item Relates to Config Item". You are using that relationship to try to relate your custom class object to a user class object.

    If you want to relate two config items, use the System.ConfigItemRelatesToConfigItem relationship class.

    Wednesday, December 31, 2014 1:03 AM