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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lionel MMSmall Business IT ConsultantCommented:
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?
netfriendsincAuthor Commented:
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.
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

netfriendsincAuthor Commented:

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 ConsultantCommented:
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
netfriendsincAuthor Commented:
Adding to the users context worked perfectly, thanks for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.