Import-PSSession serialized object

%3CLINGO-SUB%20id%3D%22lingo-sub-3118530%22%20slang%3D%22fr-FR%22%3EImport-PSSession%20serialized%20object%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3118530%22%20slang%3D%22fr-FR%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3EI'm%20trying%20to%20change%20ADUser%20password%20from%20a%20client%20computer.%20I%20ran%3A%3C%2FP%3E%3CP%3E%24s%20%3D%20new-PSSession%20(on%20domain%20controller)%3C%2FP%3E%3CP%3EImport-PSSession%20%24s%20-Activedirectory%20Module%3C%2FP%3E%3CP%3EGet-ADUser%20user%20%7C%20Set-ADAccountPassword%20-NewPassword%20(ConvertTo-SecureString%20-AsPlainText%20%22password%22%20-Force)%3C%2FP%3E%3CP%3EIt%20do%20not%20work%20because%20data%20type%20sent%20by%20(imported)%20Get-ADUser%20is%20Deserialized.Microsoft.Active%20Directory.Management.ADUser.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20a%20way%20to%20serialize%20this%20object%20and%20get%20Microsoft.Active%20Directory.Management.ADUser%20instead%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOr%20is%20there%20a%20way%20to%20pipe%20imported%20Get-ADUser%20with%20imported%20Set-ADAccountPassword%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20any%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EErald%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3118530%22%20slang%3D%22fr-FR%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3122215%22%20slang%3D%22en-US%22%3ERe%3A%20Import-PSSession%20serialized%20object%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3122215%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1297340%22%20target%3D%22_blank%22%3E%40Eraldinho%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20could%20try%20something%20like%20this%20as%20an%20alternative%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24password%20%3D%20%20Read-Host%20%22Password%3F%22%0A%24password%20%3D%20%24password%20%7C%20ConvertTo-SecureString%20-AsPlainText%20%22password%22%20-Force%0A%24username%20%3D%20Read-Host%20%22Username%3F%22%0AInvoke-Command%20-Computername%20DC%20-Credential%20(Get-Credential)%20-ScriptBlock%20%7B%0AGet-ADUser%20%24using%3Ausername%20%7C%20Set-ADAccountPassword%20-NewPassword%20%24using%3Apassword%0A%7D%20%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Visitor

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

2 Replies

@Eraldinho 

 

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
} 

 

Did this work for you?