Avatar of netfriendsinc
 asked on

Calling powershell script server 2008r2 -- Default Printer

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.
PowershellWindows Server 2008Windows 7

Avatar of undefined
Last Comment

8/22/2022 - Mon
Lionel MM

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.

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question


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!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
Lionel MM

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!