Import-PSSession serialized object

Copper Contributor

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?