Link to home
Start Free TrialLog in
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.
Avatar of Lionel MM
Lionel MM
Flag of United States of America image

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?
Avatar of netfriendsinc


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.
Avatar of Coralon
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

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!
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!