Hi,
I am trying to use Powershell to raise SCSM incidents. Each incident has a number of tasks that need to be performed and I wanted to raise these as related manual activities. Raising the incident and activity works fine but when trying to relate them it falls down. The code below is what I'm using:
$relationshipClass = Get-SCSMRelationshipClass System.WorkItemContainsActivity$ $incidentClass = Get-SCSMClass -name system.workitem.incident$
$activityClass = Get-SCSMClass -Name System.WorkItem.Activity.ManualActivity$
$myCall = Get-SCSMObject -Class $incidentClass -filter "ID -eq $myCallNo" $newAct = New-SCSMObject -Class $activityClass -PropertyHashtable @{"ID"="MA{0}";"Title"=$task.Title;"Description"=$task.Desc; "Area"="Other"; "Priority"="Medium"; "Status"="In Progress"} -Passthru New-SCSMRelationshipObject -Relationship $relationshipClass -Source $myCall -Target $newAct -Bulk -Verbose
And the result:
VERBOSE: Performing operation "New-SCSMRelationshipObject" on Target "Commit changes". VERBOSE: Adding 2da498be-0485-b2b2-d520-6ebd1698e61b to IDD VERBOSE: Performing operation "New-SCSMRelationshipObject" on Target "Commit Relationship Object". New-SCSMRelationshipObject : A discovery data item was rejected because the item is already bound to another Membership relationship. At line:1 char:27 + New-SCSMRelationshipObject <<<< -Relationship $relationshipClass -Source $myCall -Target $myAct -Bulk -Verbose + CategoryInfo : NotSpecified: (:) [New-SCSMRelationshipObject], DiscoveryDataLifetimeDependencyException + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.DiscoveryDataLifetimeDependencyException,SMLets.NewSCSMRelationshipObject
If I try to create the relationship object with -NoCommit instead of Bulk the object gets created but I am unable to then commit it. The activity never has any related objects but the incident has one of class System.WorkItem.BillableTime.
If the incident and activity are created in the SM console the objects look the same as the ones I am creating here, but there is also the require relationship object.
Has anyone had any success doing this with Powershell?