How to reset a Domain User Password with Remote Powershell

1

I want to reset my own Active Directory Password on a remote Machine (different domain).

If I use the following code snippet locally it works perfectly:

param(
    [string]$oldPassword = $(Read-Host "Old password"),
    [string]$newPassword = $(Read-Host "New password")
)
$ADSystemInfo = New-Object -ComObject ADSystemInfo
$type = $ADSystemInfo.GetType()
$user = [ADSI] "LDAP://$($type.InvokeMember('UserName', 'GetProperty', $null, $ADSystemInfo, $null))"
$user.ChangePassword($oldPassword, $newPassword)

Running following snippet on the remote machine fails:

$ADSystemInfo = New-Object -ComObject ADSystemInfo
$type = $ADSystemInfo.GetType()
Invoke-Command -Session $Session -ScriptBlock {
    param($rtype, $RemoteADSystemInfo, $OldPassword)
    $user = [ADSI] "LDAP://$($rtype.InvokeMember('UserName', 'GetProperty', $null, $RemoteADSystemInfo, $null))"
    $user.ChangePassword($OldPassword , "TestPa$$w0rd"")
} -ArgumentList $type,$ADSystemInfo,$Password
Error Message: Method invocation failed because
[Deserialized.System.RuntimeType] does not contain a method named
'InvokeMember'.
    + CategoryInfo          : InvalidOperation: (InvokeMember:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
    + PSComputerName        : test.test.domain   The following exception occurred while retrieving member "ChangePassword": "Unknown error (0x80005000)"
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMember
    + PSComputerName        : test.test.domain
powershell
active-directory
remoting
asked on Stack Overflow Dec 3, 2015 by user5633995 • edited Dec 3, 2015 by Ansgar Wiechers

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0