PSExec to script remote commands in batch

Systeinternals.com‘s team has offered a great suite of free tools that can really help manage your Windows IT systems. PSExec is a fantastic way to execute remote shell (CMD) commands on a remote system and see the results locally. With a little creativity, you can harness this to really make big jobs easier!

I have a client that I manage Windows Server Update Service (WSUS) for the patching of all servers and workstations. I needed to update group policies quickly on all the desktops on the domain. This involves running the following command: gpupdate.exe /force. But I didn’t have time to login to each PC and run that command. And there are enough PCs on the network that I wouldn’t even be able to identify them all quickly anyway.

So, I exported a CSV of all the PCs on the domain. Opened it in Excel. There is a great suite of Excel tools called KuTools (free trial) that you can use to add the additional pieces needed to generate the .bat file you’ll need.

I used KuTools to add

PSEXEC \ to the left of the PC name and gpupdate /force to the right. There are other ways to do this, some easy, some not so easy. But you have to add the text to each column.

What you wind up with looks like this

psexec \pc1 gpupdate /force

psexec \pc2 gpupdate /force

psexec \pc3 gpupdate /force

psexec \pc4 gpupdate /force

Dump the Excel contents into notepad, save the file with the .bat extension, and run the .bat file from any machine on the domain that a domain admin user logged in.

If the PC is not on the Domain (orphaned) it will simply skip it and go on to the next one. Save the file for later use!

That’s it! An easy way to update all the PCs’ GPO settings remotely!

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: