Hi Thomas,
again thanks for your original response. Theres been a bit of a delay but I've finally gotten around to trying to get the script you provided to work. Unfortunately I've had some difficulties.
I may not have been clear in describing the circumstance I need to address. Without worrying about the background, essentially I will need to replace all the relationships one user has to other objects in SCSM with relationships between a different user
and those objects, i.e. where ever the affected user was Windows.AD.User A it now needs to be Windows.AD.User B. I only need to do this for a group of about a dozen users.
So I have modified you script slightly, here's my version:
$BlacklistedRelIDs = @([guid]"649e37ab-bf89-8617-94f6-d4d041a05171")
$UserClass = Get-SCSMClass -name microsoft.ad.User
$OldUser = get-scsmObject -Class $UserClass -Filter "UserName -eq 'scsm-transition'"
$NewUser = Get-scsmObject -Class $UserClass -filter "UserName -eq 'scsm-migration'"
$SourceRels = Get-SCSMRelationshipObject -BySource $OldUser
ForEach ($Rel in $SourceRels) {
if (($BlacklistedRelIDs -notcontains [guid]($Rel.RelationshipId)) -and ($Rel.IsDeleted -eq $False)){
$RelClass = Get-SCSMRelationshipClass -id ($Rel.RelationshipId)
$TargetObject = get-scsmobject -id ($Rel.TargetObject.id)
New-scsmRelationshipObject -Relationship $Rel -Target $TargetObject -Source $NewUser -bulk
Remove-SCSMRelationshipobject $Rel
}
}
$TargetRels = Get-SCSMRelationshipObject -ByTarget $OldUser
ForEach ($Rel in $TargetRels) {
if (($BlacklistedRelIDs -notcontains [guid]($Rel.RelationshipId)) -and ($Rel.IsDeleted -eq $False)){
$RelClass = Get-SCSMRelationshipClass -id ($Rel.RelationshipId)
$SourceObject = get-scsmobject -id ($Rel.SourceObject.id)
New-scsmRelationshipObject -Relationship $Rel -Source $SourceObject -Target $NewUser -bulk
Remove-SCSMRelationshipobject $Rel
}
}
so this just uses individual fixed source and target users, but since I only need to do this for such a small group of users its not really a problem to modify the script aqnd run for each affected user.
The good news is when I run it the source user is removed from relationships with a work item, e.g I have an incident that scsm-transition is the affected user, assigned user, and primary owner on and after the script is run the history of the incident shows
that the account running the script has removed those relationships, and thescsm-transition is no longer shown as affected, assigned, or primary owner in the incident form.
The bad news is that it has not created the replacement relationships, i.e. it has not made scsm-migration the affected user, assigned user, or primary owner.
the out pout of the script in powershell is:
New-SCSMRelationshipObject : Cannot bind parameter 'Relationship'. Cannot convert the "d9683971-fad3-6874-e955-1e37aaa8651a" value of type
"Microsoft.EnterpriseManagement.Common.EnterpriseManagementRelationshipObject`1[[Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject,
Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]" to type
"Microsoft.EnterpriseManagement.Configuration.ManagementPackRelationship".
At line:19 char:47
+ New-scsmRelationshipObject -Relationship $Rel -Source $SourceObject -Target ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SCSMRelationshipObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,SMLets.NewSCSMRelationshipObject
New-SCSMRelationshipObject : Cannot bind parameter 'Relationship'. Cannot convert the "46683d3c-3f60-bc7c-22dc-544c8b6a20a7" value of type
"Microsoft.EnterpriseManagement.Common.EnterpriseManagementRelationshipObject`1[[Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject,
Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]" to type
"Microsoft.EnterpriseManagement.Configuration.ManagementPackRelationship".
At line:19 char:47
+ New-scsmRelationshipObject -Relationship $Rel -Source $SourceObject -Target ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SCSMRelationshipObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,SMLets.NewSCSMRelationshipObject
New-SCSMRelationshipObject : Cannot bind parameter 'Relationship'. Cannot convert the "5d194ac6-1f5c-29b6-f41d-8cf9fb202b91" value of type
"Microsoft.EnterpriseManagement.Common.EnterpriseManagementRelationshipObject`1[[Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject,
Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]" to type
"Microsoft.EnterpriseManagement.Configuration.ManagementPackRelationship".
At line:19 char:47
+ New-scsmRelationshipObject -Relationship $Rel -Source $SourceObject -Target ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SCSMRelationshipObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,SMLets.NewSCSMRelationshipObject
New-SCSMRelationshipObject : Cannot bind parameter 'Relationship'. Cannot convert the "a1af6514-6003-f946-66d1-c1adf3aa0808" value of type
"Microsoft.EnterpriseManagement.Common.EnterpriseManagementRelationshipObject`1[[Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject,
Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]" to type
"Microsoft.EnterpriseManagement.Configuration.ManagementPackRelationship".
At line:19 char:47
+ New-scsmRelationshipObject -Relationship $Rel -Source $SourceObject -Target ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SCSMRelationshipObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,SMLets.NewSCSMRelationshipObject
New-SCSMRelationshipObject : Cannot bind parameter 'Relationship'. Cannot convert the "4f540b48-4750-f47b-f69d-fbea3bb2ed58" value of type
"Microsoft.EnterpriseManagement.Common.EnterpriseManagementRelationshipObject`1[[Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject,
Microsoft.EnterpriseManagement.Core, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]" to type
"Microsoft.EnterpriseManagement.Configuration.ManagementPackRelationship".
At line:19 char:47
+ New-scsmRelationshipObject -Relationship $Rel -Source $SourceObject -Target ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [New-SCSMRelationshipObject], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,SMLets.NewSCSMRelationshipObject
Remove-SCSMRelationshipobject : Cannot process extension elements as EnterpriseManagementObject. User EnterpriseManagementObjectProjection for all extension
element CRUD operations.
At line:20 char:6
+ Remove-SCSMRelationshipobject $Rel
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (4f540b48-4750-f47b-f69d-fbea3bb2ed58:Guid) [Remove-SCSMRelationshipObject], InvalidOperationException
+ FullyQualifiedErrorId : Object,SMLets.RemoveSMRelationshipObjectCommand
Do you have any suggestion as to what I've got wrong?
Thanks Eden
-
Edited by
Eden Ravenwood
Thursday, February 05, 2015 11:39 PM
clarity