locked
SCSM 2012 SP1. Need a simple example of using SMLets to operate with objects, object propertys and relationships RRS feed

  • Question

  • I have learned many examples and topics about subject (like this or this), but can't find any simple example to resolve my task.

    Simple example of task - Have a service request. Need to get values of  "Title" and "Related Items -> Configuration Item" and put this values to "Description" of the source SR.

    Can anybody post here a simple example of Powershell-code with using SMlets (Get-SCSMObject, Get-SCSMClass, Get-SCSMRelationShipObject etc.) to resolve this task? That can help me deeper understand manipulating with objects in SCSM. Now I can only to get parameters using this: http://www.codeproject.com/Articles/61900/PowerShell-and-XML But it is not enough. Thank you for help!

    Wednesday, March 13, 2013 10:18 AM

Answers

  • Import-Module SMLets
    $ServiceRequestID = "SR802"
    $ServiceRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -Filter "ID -eq $ServiceRequestID"
    $GetRelatedConfigurationItem = (Get-SCSMRelationshipObject -BySource $ServiceRequest | ?{$_.RelationshipID -eq "d96c8b59-8554-6e77-0aa7-f51448868b43"}).TargetObject.DisplayName
    $GetServiceRequestTitle = $ServiceRequest.Title
    $ServiceRequest | Set-SCSMObject -Property Description -Value "$GetServiceRequestTitle $GetRelatedConfigurationItem"

    Result:

    • Marked as answer by Dismantled Wednesday, March 13, 2013 7:45 PM
    • Edited by Dismantled Wednesday, March 13, 2013 8:02 PM
    Wednesday, March 13, 2013 7:45 PM

All replies

  • Import-Module SMLets
    $ServiceRequestID = "SR802"
    $ServiceRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -Filter "ID -eq $ServiceRequestID"
    $GetRelatedConfigurationItem = (Get-SCSMRelationshipObject -BySource $ServiceRequest | ?{$_.RelationshipID -eq "d96c8b59-8554-6e77-0aa7-f51448868b43"}).TargetObject.DisplayName
    $GetServiceRequestTitle = $ServiceRequest.Title
    $ServiceRequest | Set-SCSMObject -Property Description -Value "$GetServiceRequestTitle $GetRelatedConfigurationItem"

    Result:

    • Marked as answer by Dismantled Wednesday, March 13, 2013 7:45 PM
    • Edited by Dismantled Wednesday, March 13, 2013 8:02 PM
    Wednesday, March 13, 2013 7:45 PM
  • If ConfigItem has more objects you would need a foreach also. But I think Powershell 3.0 can handle it though
    Thursday, March 14, 2013 10:33 AM
  • Heh, sure :)!

    Powershell 2.0 is enough ;).

    ...
    [xml] $GetValuesRO = $GetInput.UserInputs.UserInput | Where-Object {$_.Question -eq "Read-Only Users"} | %{$_.Answer}
    $GetUserNameRO = $GetValuesRO.Values.Value | %{$_.DisplayName}
    $GetUserNameRO = $GetUserNameRO -join "; "
    ...


    Friday, March 15, 2013 8:11 PM