2

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.

Jeff
  • 4,285
  • 15
  • 63
  • 115
  • 1
    What happens when you try to run it with PSEXEC? – aphoria Nov 05 '12 at 16:02
  • It works. Push come to shove, I'll have to do that, but I don't like dependancies. – Jeff Nov 05 '12 at 16:09
  • How are you running the other commands? – aphoria Nov 05 '12 at 16:10
  • My other commands have a built in remote switch: reg add \\SERVERNAME\HKLM\... or sc \\SERVERNAME stop snmp – Jeff Nov 05 '12 at 16:15
  • Just to clarify - you want to actually run the command at your machine and have it affect the remote machine, correct? As opposed to putting the command in the batch file, put the batch file on the remote machine, then have the batch file run on that remote machine? .................. There are other tools apart from psexec of course, e.g. plink, but you're asking for a native method of doing it so that's no help to you. – lessthanideal Nov 05 '12 at 16:36
  • @lessthanideal - Yes. Ideally, I would run this file on my local machine and affect any server I put in the command. – Jeff Nov 05 '12 at 16:39

1 Answers1

6

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"
Alex Nolasco
  • 18,750
  • 9
  • 86
  • 81
dugas
  • 12,025
  • 3
  • 45
  • 51
  • +1. @Jeff: Please see this for usage of Invoke-Command in this case [Using Powershell's Invoke-Command to call a batch file with arguments](http://stackoverflow.com/questions/8541809/using-powershells-invoke-command-to-call-a-batch-file-with-arguments) – Victor Zakharov Nov 05 '12 at 16:05
  • +1 for powershell. I should be using that, but I'm stuck in a .bat environment at the moment. – Jeff Nov 05 '12 at 16:08
  • 1
    @Jeff - since your post was tagged with powershell, I assumed you were looking for a powershell solution. – dugas Nov 05 '12 at 16:10
  • @dugas - That makes sense. I like powershell, and this may be the best solution. – Jeff Nov 05 '12 at 16:17