Calling powershell script server 2008r2 -- Default Printer

netfriendsinc used Ask the Experts™
I have a 2012r2 print server with about 30 printers that I assign to specific OUs via "launch with Group Policy" from the printer management snapin.  I then assign the specific printers to their corresponding OUs.  That works fine.  However, from what I've read you can't create a default printer if you assign printers that way.  So, I created a powershell script, tested it locally (worked) and then went to the specific OU on a 2008r2 server, computer config --> policies --> windows settings --> scripts and added it to the powershell scripts tab and told windows to "run windows powershell scripts first"  

The workstations in that particular OU are receiving the GPO with the default printer powershell script however, they aren't setting the default printer.  Yet if I run the script locally from the desktop, it works without issue and sets the default printer.  All workstations are Windows 7 enterprise.  I've attached the power shell script code below (wouldn't allow upload) as well (with server and printer names set to "server" and "printer" for security).  

Set-ExecutionPolicy Bypass
$TargetPrinter = "\\server\printer"
$ErrorActionPreference = “SilentlyContinue”

$LocalPrinter = GWMI -class Win32_Printer |

Where {$_.Name -eq $TargetPrinter}


Again, the above script works without issue locally, just not via the GPO even though running rsop.msc confirms it ran.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Lionel MMSmall Business IT Consultant

Do you have any logging in your script to see if it is actually running but not doing anything? If you are running a log of the results what does it say, anything?


There isn't any logging in the script -- would you know how to implement that?  I do know that the GPO is processed by running rsop.msc -- it says "applied" but then the default printer doesn't change.. yet the script works perfectly when run manually.
Senior Citrix Engineer
The problem is that the default printer setting is a user setting.

You need to have the script run under the user's context.  You can assign your script as a login script to the user's OU, or you can turn on loopback processing with a merge (or replace) option.

You could also have the script run from the Run registry key in the USER hive (HKCU\Software\Microsoft\Windows\CurrentVersion\Run), or put a shortcut to it in c:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup.  

You might want to reconsider using Powershell in this circumstance.  Generally powershell makes a fairly poor login script platform because of the major overhead in loading the libraries, etc. In this circumstance, vbScript is going to be a substantially faster option

JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.



Great info thank you.  I have a VBscript that worked, but I had attached it to the computer context -- I'm betting now that if i put it under the user's section it will work.  I'll play with that and report back.. Thanks!
Lionel MMSmall Business IT Consultant

you can add logging by defining your output file
$Printer_GPO_File = "C:\Utils\PrintersViaGPO.txt"
and then adding this to end of the command you run
| $Printer_GPO_File


Adding to the users context worked perfectly, thanks for the help!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial