I'm trying to use New-SCSMRelationshipObject to create a System.WorkItemRelatesToRequestOffering relationship object. When I remove the management pack that contains all of my request offerings incidents that had relationships with those objects lose them. I'd like to keep these relationships, so I'm writing a script that pulls all the data for all objects in our system, and then makes my management pack changes, and fixes any data loss that occurred; I have it working for everything except this relationship.
I found this example of someone creating a relationship for the createdby relationship:
https://social.technet.microsoft.com/forums/systemcenter/en-US/9c0e0ee5-f14c-4399-9012-c488f05afb75/how-to-use-scsmnewrelationshipobject-with-smlets
From that example I gleaned this:
$CreatedByRelClass = Get-SCSMRelationshipClass System.WorkItemCreatedByUser$ $CRClass = Get-SCSMClass -Name System.WorkItem.ChangeRequest $ChangeReq = Get-SCSMObject $CRClass -Filter "Id -eq CR45" $UserClass = Get-SCSMClass -Name System.Domain.User $CreatedByUser = Get-SCSMObject $UserClass -Filter "UserName -eq stestuser" New-SCSMRelationshipObject -RelationShip $CreatedByRelClass -Source $ChangeReq -Target $CreatedByUser -Bulk
Using this example, I tried this:
$RelationshipObjectClass = Get-SCSMRelationshipClass -name System.WorkItemRelatesToRequestOffering $SRClass = Get-SCSMClass -Name System.WorkItem.ServiceRequest $ServiceReq = Get-SCSMObject $SRClass -Filter "Id -eq SR39" $RequestOff = Get-SCSMClass -Name System.RequestOffering $RelatedRequestOff = Get-SCSMObject $RequestOff -Filter "DisplayName -eq 'Finance Service Request'" New-SCSMRelationshipObject -RelationShip $RelationshipObjectClass -Source $ServiceReq -Target $RelatedRequestOff -Bulk
However, I'm getting an error:
New-SCSMRelationshipObject : Cannot process extension elements as EnterpriseManagementObject. User EnterpriseManagementObjectProjection for all
extension element CRUD operations.
At line:1 char:1
+ New-SCSMRelationshipObject -RelationShip $RelationshipObjectClass -Source $Servi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Enter...ationshipObject:CreatableEnterp...ationshipObject) [New-SCSMRelationshipObject],
InvalidOperationException
+ FullyQualifiedErrorId : Relationshipship Error,SMLets.NewSCSMRelationshipObject
This made me think that perhaps I should be using the projections, so I switched my "source" and "target" object to be the projections, and go this error instead:
New-SCSMRelationshipObject : Cannot bind parameter 'Source'. Cannot convert the
"@{__base=Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectProjection; Object=SR39 ..." (I abbreviated this, but it basically spits out the entire object.)
value of type "EnterpriseManagementObjectProjection#System.WorkItem.ServiceRequestProjection" to type "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject".
At line:1 char:75
+ New-SCSMRelationshipObject -Relationship $RelationshipObjectClass -Source $Sourc ...
+
~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SCSMRelationshipObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,SMLets.NewSCSMRelationshipObject
I double checked that the target and source class types are all correct, I noticed the relationship's source class type is "System.Workitem", but if you look at an actual relationship object, the source class type is "System.Workitem.ServiceRequest", however this is also the case with the example above too. I can't any examples of people creating this particular relationship, so if anyone has, I'd love to see your examples, I'm confused why I can't get it to work.
- Edited by _Keith_ Wednesday, January 21, 2015 8:43 PM