Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Remoting with credential

While running remoting commands like Enable-PsSession, Invoke-command etc. we need to provide credentials with those commands.

I don't want to provide the credentials every time while executing these command.

Also lets say I stored the username in variable & using the variable while executing the command. I want to do this for the password as well. Could I do that ?

Eg:

Invoke-Command -ComputerName mycomputer -ScriptBlock { Get-ChildItem C:\ } -credential  mydomain\administrator

So here I am providing the password everytime while executing these command.

How should the commands take username & password automatically either from variable & some other mechanism ?

like image 789
usr021986 Avatar asked Aug 05 '13 08:08

usr021986


1 Answers

You can do:

$cred = get-credential #fill you credential in the pop-up window

and then:

Invoke-Command -ComputerName mycomputer -ScriptBlock { Get-ChildItem C:\ } -credential $cred

Remember that the password in $cred is easily recoverable in clear text!

like image 187
CB. Avatar answered Sep 29 '22 14:09

CB.