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 ?