I'd like to restart a remote computer that belongs to a domain. I have an administrator account but I don't know how to use it from powershell.
I know that there is a Restart-Computer
cmdlet and that I can pass credential but if my domain is for instance mydomain
, my username is myuser
and my password is mypassword
what's the right syntax to use it?
I need to schedule the reboot so I don't have to type the password.
Best Answer
The problem with
Get-Credential
is that it will always prompt for a password. There is a way around this however but it involves storing the password as a secure string on the filesystem.The following article explains how this works:
In summary, you create a file to store your password (as an encrypted string). The following line will prompt for a password then store it in
c:\mysecurestring.txt
as an encrypted string. You only need to do this once:Wherever you see a
-Credential
argument on a PowerShell command then it means you can pass aPSCredential
. So in your case:You may need a different
-Authentication
switch value because I don't know your environment.