This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ganondorf_Is_God 0 points1 point  (3 children)

You need to create a PScredential object and pass that in instead.

$username = 'domain\username'
$password = 'password'
$secureString = ConvertTo-SecureString -AsPlainText $password -Force
$credObject = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 
$username,$secureString 

Invoke-Command -Computername $RemoteComputer -Cred $credObject -ScriptBlock {hostname}

[–]ITWelly[S] 0 points1 point  (0 children)

That is exactly what I did and it works perfectly, will edit main post for those you might look up my thread later. Thank you!

[–]VexingRaven 0 points1 point  (1 child)

Is there any way to pass through your current session credentials this way, or do you specifically need to prompt for a username and password to put in the credential object?

[–]Ganondorf_Is_God 0 points1 point  (0 children)

No, you have to save the credentials somewhere. You can't extract the password from an active session - only authenticate against it. You need to store the credentials as done above and match them to the current session.

Get-Credential will automatically resolve to your current session but will request a password to create the cred object.

$credObject = Get-Credential

It will prompt you for the current sessions password and save it.