Feb 04 2022 10:41 AM
Hi,
I'm trying to change ADUser password from a client computer. I ran:
$s = new-PSSession (on domain controller)
Import-PSSession $s -Module activedirectory
Get-ADUser user | Set-ADAccountPassword -NewPassword (ConvertTo-SecureString -AsPlainText "password" -Force)
It do not work because data type sent by (imported) Get-ADUser is Deserialized.Microsoft.ActiveDirectory.Management.ADUser.
Is there a way to serialize this object and get Microsoft.ActiveDirectory.Management.ADUser instead?
Or is there a way to pipe imported Get-ADUser with imported Set-ADAccountPassword
Thanks for any help.
Erald
Feb 06 2022 03:21 AM
You could try something like this as an alternative?
$password = Read-Host "Password?"
$password = $password | ConvertTo-SecureString -AsPlainText "password" -Force
$username = Read-Host "Username?"
Invoke-Command -Computername DC -Credential (Get-Credential) -ScriptBlock {
Get-ADUser $using:username | Set-ADAccountPassword -NewPassword $using:password
}