We help IT Professionals succeed at work.

PowerShell

Medium Priority
682 Views
Last Modified: 2012-05-12
I am in an urgent need of a powershell that would run against a list of omputers in computers.exe and add a domain user to the local administrators group of all computers in the text file.
Please help.

Thank you,
Paul
Comment
Watch Question

Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
It is much easier if you use PsExec from www.sysinternals.com, as remote executing PS commands requires you to use WMI or Remoting (WinRM):
psexec @computers.txt -u YourDomain\Administrator -p AdminPwd -d net localgroup administrators YourDomain\YourUser /add

Open in new window

That will run with the highest possible speed, not waiting for the individual results.

Author

Commented:
Thanks Qlemo for your assistance. But, I'm not familiar with Psexec and I don't know how to use it by WMI.
I am more looking for a powershell code.

Paul
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
You do not need to be familiar with PsExec, just run the command as shown.

If you insist on PowerShell:
gc computers.txt | % { invoke-command -ComputerName $_ {net localgroup administrators YourDomain\YourUser /add} }

Open in new window

See   get-help invoke-command -examples   and   get-help about_remote   for more details.

Author

Commented:
This is the error I got: error
"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
As said, WinRM is required to be configured on all remote targets. Follow the instructions given in the error message to allow to use WinRM.

Author

Commented:
Thanks Qlemo. Can you plz briefly explain me what is the functionality of WinRM?

Paul

Author

Commented:
Thanks Qlemo. Can you plz briefly explain me what is the functionality of WinRM?

Paul
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
WinRM allows to send commands via HTTPS (SSL encoded HTTP). More about it can be found at http://msdn.microsoft.com/en-us/library/windows/desktop/aa384426(v=vs.85).aspx .
PowerShell sends commands via SOAP to WinRM to execute them independent from the local PowerShell process. It is even used for some local commands like job control (background tasks).

Explore More ContentExplore courses, solutions, and other research materials related to this topic.