Update group policy (or run any command) remotely using Powershell

This script allows you to run any command remotely using Powershell on your network. I usually use this to update group policy configurations on all PCs on my network remotely.

Note: In Windows Server 2012 & Windows Server 2012 R2, you can run the Invoke-GPUpdate PowerShell cmdlet ro refresh group policy on any Windows 8 computers on your network. More information here.

What you will need:

What this script does:

  • Remotely runs gpupdate /force on all workstations
  • Selects "N" if it asks to logoff user

When you run it, you’ll see some output like: Starting cmd on PC1-USRNAME... on PC1-USRNAME... cmd exited on PC1-USRNAME with error code 0.

error code 0” means it has completed successfully without any errors.

Additional syntax:

  • To run this script only on a specific computer, e.g., PC1-USRNAME, replace "\\*" with "\\PC1-USRNAME" as shown below: PsExec.exe \\PC1-USRNAME -s cmd /C echo N | gpupdate /force
  • To force a logoff after updating the group policy settings, use this: PsExec.exe \\* -s cmd /C echo Y | gpupdate /force
  • To run any other command remotely, simply use the following syntax: PsExec.exe \\* -s cmd /C
  • For example, to create a directory in all workstations, simply run: PsExec.exe \\* -s cmd /C mkdir C:\test

(header image source: interfaceit.com)

Leave a Comment