locked
Duplicate Users after domain migration RRS feed

  • Question

  • Hello,

    We have one AD forest and are currently migrating our users from our two sub domains to the root domain.

    After the user has been migrated to the root domain they appear twice in Service Manager.  Checking the properties of both users in SM shows one is from the original sub domain and the other is the newly migrated user in the root domain.

    If I go to Configuration Items – Users, then try and delete the sub domain user it reappears a short while later.

    Also, we have an incident subscription setup which sends an email to the analyst when the affected user adds a comment.  This has stopped working for affected users that have been migrated.  I assume this is because of the issue above but not sure how to fix it?

    Can anyone advise how to handle this scenario?

    Thanks

    Thursday, August 2, 2018 8:03 PM

Answers

  • If the old and new username is the same and just the name of the domain is different you can give it a try with this script:

    [CmdletBinding()]
    Param(
      [Parameter(Mandatory=$True,Position=1)]
       [string]$oldADUser,
     
       [Parameter(Mandatory=$True)]
       [string]$newADUser
    )
    
    
    $oldADUserDomain,$oldADUserName = $oldADUser.split('\')
    $oldADUser = "$oldADUserDomain.$OldADUserName"
    
    $newADUserDomain,$newADUserName = $newADUser.split('\')
    $newADUser = "$newADUserDomain.$newADUserName"
    
    $relatedItems = ""
    
    if (!(Get-module System.Center.Service.Manager)) 
        {
         #TODO: You may need to alter the location of the PowerShell Module:
         import-module 'C:\Program Files\Microsoft System Center\Service Manager\PowerShell\System.Center.Service.Manager.psd1';
        }
    
    #Get the old and new user objects from the CMDB
    $oldName = Get-SCClassInstance -Class (Get-SCClass -Name "System.Domain.User") -Filter "Name -eq $oldADUser";
    $newName = Get-SCClassInstance -Class (Get-SCClass -Name "System.Domain.User") -Filter "Name -eq $newADUser";
    
    $oldName
    $newName
    
    if (!$oldName)
        {
        Write-Host "Old User not found in SCSM"
        Break
        }
    if (!$newName)
        {
        Write-Host "New User not found in SCSM"
        Break
        }
    
    
    #Get relationships targeted at the old user object
    $relatedItems = Get-SCRelationshipInstance -TargetInstance $oldName;
    
    foreach ($item in $relatedItems)
        {
         #Figure out the type of each of those relationships & check against the list
         $relType = Get-SCRelationship -Id ($item.RelationshipId);
         if ($relType.Name -eq "System.WorkItem.TroubleTicketClosedByUser" -or
          $relType.Name -eq "System.WorkItemAffectedUser" -or
          $relType.Name -eq "System.WorkItemCreatedByUser" -or
          $relType.Name -eq "System.WorkItemAssignedToUser" -or
          $relType.Name -eq "System.WorkItem.TroubleTicketResolvedByUser" -or
          $relType.Name -eq "System.ConfigItemOwnedByUser")
             {
              #delete the old relationships & recreate them with the new user object
              Remove-SCSMRelationshipInstance -Instance $item;
              New-SCRelationshipInstance -RelationshipClass (Get-SCRelationship -Name $relType.Name) -Source $item.SourceObject -Target $newName;
             }
        }

    Start the script this way:

    Switch-OldUserNewUser.ps1 -oldADUser "<olddomain>\dduck" -newADUser "<newdomain>\dduck"

    Hope this helps.


    Andreas Baumgarten

    Wednesday, August 15, 2018 8:49 PM

All replies

  • The pimary key of the SCSM Config Item Windows User is the combination of Domain and Username. For that reason you get duplicates for each migrated user. "Subdomain\paul" is different for SCSM than "Domain\paul".

    As long as users will be synced by the AD Connector, from old and new domain, you will get this duplicates.

    As SCSM is working with GUIDs internally for all objects "Subomain\paul" has a different GUID than "Domain\paul". All relationships between objects are based on the GUIDs of the objects. If you delete the object "Subdomain\paul" you will loose any relationship to other objects like "is affected user" of IR1234.

    The only option you have is to delete/renew the relationships. This can be done by PowerShell as long as both user objects are available in SCSM.

    Maybe this blog post is helpful for you:

    Managing username changes in Service Manager

     

     

    Andreas Baumgarten

    Monday, August 6, 2018 10:58 AM
  • Thanks for the response.  The link you posted seems to match my scenario but the script is failing when i try and run it.

    I get the error below when i run the command with correct username.  Any idea what i'm doing wrong here?  I've tried it with jbloggs@domain.com as well but get the same result.  


    .\Move-Relationships.ps1 -oldADUser "subdomain\jbloggs" -newADUser "domain\jbloggs"


    Get-SCRelationshipInstance : Cannot validate argument on parameter
    'TargetInstance'. The argument is null. Provide a valid value for the
    argument, and then try running the command again.
    At C:\Scripts\Move-Relationships.ps1:21 char:60
    + $relatedItems = Get-SCRelationshipInstance -TargetInstance $oldName;
    +                                                            ~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Get-SCRelationshipInstance], P
       arameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Syste
       mCenter.Core.Commands.GetSCRelationshipInstanceCommand
    Wednesday, August 15, 2018 9:33 AM
  • The error message looks like the script can't find the OldUser.

    You have to provide the username only. No domain in front and not the UPN.

    I modified the script a little bit to ceheck if both usersl the old and the new one, are in SCSM.

    [CmdletBinding()]
    Param(
      [Parameter(Mandatory=$True,Position=1)]
       [string]$oldADUser,
     
       [Parameter(Mandatory=$True)]
       [string]$newADUser
    )
    
    if (!(Get-module System.Center.Service.Manager)) 
        {
         #TODO: You may need to alter the location of the PowerShell Module:
         import-module 'C:\Program Files\Microsoft System Center\Service Manager\PowerShell\System.Center.Service.Manager.psd1';
        }
    
    #Get the old and new user objects from the CMDB
    $oldName = Get-SCClassInstance -Class (Get-SCClass -Name "System.Domain.User") -Filter "UserName -eq $oldADUser";
    $newName = Get-SCClassInstance -Class (Get-SCClass -Name "System.Domain.User") -Filter "UserName -eq $newADUser";
    
    if (!$oldName)
        {
        Write-Host "Old User not found in SCSM"
        Break
        }
    if (!$newName)
        {
        Write-Host "New User not found in SCSM"
        Break
        }
    
    
    #Get relationships targeted at the old user object
    $relatedItems = Get-SCRelationshipInstance -TargetInstance $oldName;
    
    foreach ($item in $relatedItems)
        {
         #Figure out the type of each of those relationships & check against the list
         $relType = Get-SCRelationship -Id ($item.RelationshipId);
         if ($relType.Name -eq "System.WorkItem.TroubleTicketClosedByUser" -or
          $relType.Name -eq "System.WorkItemAffectedUser" -or
          $relType.Name -eq "System.WorkItemCreatedByUser" -or
          $relType.Name -eq "System.WorkItemAssignedToUser" -or
          $relType.Name -eq "System.WorkItem.TroubleTicketResolvedByUser" -or
          $relType.Name -eq "System.ConfigItemOwnedByUser")
             {
              #delete the old relationships & recreate them with the new user object
              Remove-SCSMRelationshipInstance -Instance $item;
              New-SCRelationshipInstance -RelationshipClass (Get-SCRelationship -Name $relType.Name) -Source $item.SourceObject -Target $newName;
             }
        }

    Start the script like this:

    Switch-OldUserNewUser.ps1 -oldADUser "mmouse" -newADUser "dduck"

    Hope this helps.


    Andreas Baumgarten

    Wednesday, August 15, 2018 12:16 PM
  • Thanks,

    I get the error below when i try to run that script.  Just to be clear.  The user which has been duplicated in SM was migrated from the subdomain to the rootdomain.  No change has been made to the username.  it was jbloggs in the subdomain (Source) and is still jbloggs in the target domain.  If I start the script as below i don't see how it can differentiate between the duplicate accounts in SM.  Sorry if i'm missing something simple here!

    Switch-OldUserNewUser.ps1 -oldADUser "jbloggs" -newADUser "jbloggs"

    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand
    
    New-SCRelationshipInstance : Cannot convert 'System.Object[]' to the type
    'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject' required by
    parameter 'Target'. Specified method is not supported.
    At C:\Scripts\SwitchOldUser2.ps1:48 char:133
    + ... Object -Target $newName;
    +                    ~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [New-SCRelationshipInstance
       ], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.SystemCenter.Cor
       e.Commands.NewSCSMRelationshipInstanceCommand

    Wednesday, August 15, 2018 1:29 PM
  • If the old and new username is the same and just the name of the domain is different you can give it a try with this script:

    [CmdletBinding()]
    Param(
      [Parameter(Mandatory=$True,Position=1)]
       [string]$oldADUser,
     
       [Parameter(Mandatory=$True)]
       [string]$newADUser
    )
    
    
    $oldADUserDomain,$oldADUserName = $oldADUser.split('\')
    $oldADUser = "$oldADUserDomain.$OldADUserName"
    
    $newADUserDomain,$newADUserName = $newADUser.split('\')
    $newADUser = "$newADUserDomain.$newADUserName"
    
    $relatedItems = ""
    
    if (!(Get-module System.Center.Service.Manager)) 
        {
         #TODO: You may need to alter the location of the PowerShell Module:
         import-module 'C:\Program Files\Microsoft System Center\Service Manager\PowerShell\System.Center.Service.Manager.psd1';
        }
    
    #Get the old and new user objects from the CMDB
    $oldName = Get-SCClassInstance -Class (Get-SCClass -Name "System.Domain.User") -Filter "Name -eq $oldADUser";
    $newName = Get-SCClassInstance -Class (Get-SCClass -Name "System.Domain.User") -Filter "Name -eq $newADUser";
    
    $oldName
    $newName
    
    if (!$oldName)
        {
        Write-Host "Old User not found in SCSM"
        Break
        }
    if (!$newName)
        {
        Write-Host "New User not found in SCSM"
        Break
        }
    
    
    #Get relationships targeted at the old user object
    $relatedItems = Get-SCRelationshipInstance -TargetInstance $oldName;
    
    foreach ($item in $relatedItems)
        {
         #Figure out the type of each of those relationships & check against the list
         $relType = Get-SCRelationship -Id ($item.RelationshipId);
         if ($relType.Name -eq "System.WorkItem.TroubleTicketClosedByUser" -or
          $relType.Name -eq "System.WorkItemAffectedUser" -or
          $relType.Name -eq "System.WorkItemCreatedByUser" -or
          $relType.Name -eq "System.WorkItemAssignedToUser" -or
          $relType.Name -eq "System.WorkItem.TroubleTicketResolvedByUser" -or
          $relType.Name -eq "System.ConfigItemOwnedByUser")
             {
              #delete the old relationships & recreate them with the new user object
              Remove-SCSMRelationshipInstance -Instance $item;
              New-SCRelationshipInstance -RelationshipClass (Get-SCRelationship -Name $relType.Name) -Source $item.SourceObject -Target $newName;
             }
        }

    Start the script this way:

    Switch-OldUserNewUser.ps1 -oldADUser "<olddomain>\dduck" -newADUser "<newdomain>\dduck"

    Hope this helps.


    Andreas Baumgarten

    Wednesday, August 15, 2018 8:49 PM
  • Great, thanks that last script worked.

    I had 200 users to run the script on.  Around 10 of those users came back with a few errors below.  Despite the error it seems to have gone through ok.  I assume i can just ignore the error?

    Thanks for your help with this.

    New-SCRelationshipInstance : Cannot validate argument on parameter 'Source'.
    The argument is null or empty. Provide an argument that is not null or empty,
    and then try the command again.
    At C:\Scripts\SwitchOldUser3.ps1:60 char:106
    + ... .Name) -Source $item.SourceObject -Target $newName;
    +                    ~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [New-SCRelationshipInstance], P
       arameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Syste
       mCenter.Core.Commands.NewSCSMRelationshipInstanceCommand
    
    Remove-SCSMRelationshipInstance : Object reference not set to an instance of
    an object.
    At C:\Scripts\SwitchOldUser3.ps1:59 char:11
    +           Remove-SCSMRelationshipInstance -Instance $item;
    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (Microsoft.Syste...InstanceCommand
       :RemoveSCRelationshipInstanceCommand) [Remove-SCRelationshipInstance], Nul
      lReferenceException
        + FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.Core.Comma
       nds.RemoveSCRelationshipInstanceCommand
    


     

    Thursday, August 16, 2018 3:33 PM