Powershell – Can you run remote commands without psexec

batch-filepowershellpsexec

I am attempting to run a batch file on several remote machines. It has some registry changes and other commands that I am able to run remotely. I have one command I have not been able to figure out an alternative:

net user USERNAME /PASSWORDREQ:yes

Is there a way to run this command remotely without psexec? I'd rather not distribute my batch file with a dependancy.

Best Answer

Yes, you can enable powershell remoting on the remote computers, and then use the Invoke-Command cmdlet. Example:

Invoke-Command -ComputerName RemoteComputer -Script { param($userName) net use $userName /PASSWORDREQ:yes } -Args "UserNameArgumentValue"
Related Topic