diff --git a/src/public/Move-ADSIComputer.ps1 b/src/public/Move-ADSIComputer.ps1 index b02b819..263f27b 100644 --- a/src/public/Move-ADSIComputer.ps1 +++ b/src/public/Move-ADSIComputer.ps1 @@ -86,7 +86,11 @@ function Move-ADSIComputer #$Computer.GetUnderlyingObject() # Create DirectoryEntry object - $NewDirectoryEntry = New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$Destination" + $ArgumentList = "LDAP://$Destination" + if ($PSBoundParameters['Credential']) { + $ArgumentList = $ArgumentList, $Credential.UserName, $Credential.GetNetworkCredential().Password + } + $NewDirectoryEntry = New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList $ArgumentList # Move the computer $Computer.GetUnderlyingObject().psbase.moveto($NewDirectoryEntry) diff --git a/src/public/Move-ADSIGroup.ps1 b/src/public/Move-ADSIGroup.ps1 index 0574984..1a08af2 100644 --- a/src/public/Move-ADSIGroup.ps1 +++ b/src/public/Move-ADSIGroup.ps1 @@ -89,9 +89,13 @@ function Move-ADSIGroup } # Create DirectoryEntry object - $NewDirectoryEntry = New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$Destination" + $ArgumentList = "LDAP://$Destination" + if ($PSBoundParameters['Credential']) { + $ArgumentList = $ArgumentList, $Credential.UserName, $Credential.GetNetworkCredential().Password + } + $NewDirectoryEntry = New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList $ArgumentList - # Move the computer + # Move the group $Group.GetUnderlyingObject().psbase.moveto($NewDirectoryEntry) $Group.Save() diff --git a/src/public/Move-ADSIUser.ps1 b/src/public/Move-ADSIUser.ps1 index 261cf5e..597d92f 100644 --- a/src/public/Move-ADSIUser.ps1 +++ b/src/public/Move-ADSIUser.ps1 @@ -94,9 +94,13 @@ function Move-ADSIUser #$User.GetUnderlyingObject() # Create DirectoryEntry object - $NewDirectoryEntry = New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList "LDAP://$Destination" + $ArgumentList = "LDAP://$Destination" + if ($PSBoundParameters['Credential']) { + $ArgumentList = $ArgumentList, $Credential.UserName, $Credential.GetNetworkCredential().Password + } + $NewDirectoryEntry = New-Object -TypeName System.DirectoryServices.DirectoryEntry -ArgumentList $ArgumentList - # Move the computer + # Move the user $User.GetUnderlyingObject().psbase.moveto($NewDirectoryEntry) $User.Save() }