Share via


Remove network printer in a logon script

Question

Monday, August 27, 2012 2:47 PM

Hello

I'm using a powershell script push by a GPO.

I want to be able to remove all network printers at logon and then remapped printers based on IP address.

To remove printer i'm using the following command : Get-WMIObject Win32_Printer | where{$_.Network -eq 'true'} | foreach{$_.delete()}

It's working perfectly when i'm running the command in a user session but for some reason, it doesn't seem to work, it looks like Windows is not ready or something...

Is there a way to run this command in a logon script?

Thanks

All replies (6)

Monday, August 27, 2012 4:00 PM ✅Answered | 1 vote

Use Scheduled Task

http://jrich523.wordpress.com/2010/05/25/run-a-powershell-script-from-a-unc-path-via-task-scheduler-in-windows-2008/

http://www.grouppolicy.biz/2010/01/how-to-schedule-a-delayed-start-logon-script-with-group-policy/

Or more simple

User Configuration\Policies\Windows Settings\Scripts    Logon (PowerShell Scripts tab)

http://technet.microsoft.com/sv-se/library/dd367856(v=ws.10).aspx

Сазонов Илья http://isazonov.wordpress.com/


Thursday, August 30, 2012 8:27 AM ✅Answered

Hi,

We could use Group Policy to deploy logon script, but if you use logon script to map printers and also want to use logon script to remove printers, there may be issues, if those printers are already mapped, and then we could use Logon script to remove them.

Remove local / network printers possible with GPP ?

http://social.technet.microsoft.com/Forums/en-US/winserverGP/thread/859d8838-46e2-4bc9-843d-6ff2e9e75f9f

Remove Printer Script windows 7

http://social.technet.microsoft.com/Forums/en/w7itproinstall/thread/b577a47f-bac9-411a-8c71-01723ff8c341

Hope this helps.

Regards,

Yan Li

Yan Li

TechNet Community Support


Monday, August 27, 2012 3:02 PM

I assume that there are mapped printers created when the user logs on.  If your script tries to remove them before they are created, it won't work.  Try putting a pause at the start of the script of about 1 second.

Start-Sleep 1

Grant Ward, a.k.a. Bigteddy


Monday, August 27, 2012 3:03 PM

Run script by GPP with Run in logged-on user's security context option on

Сазонов Илья http://isazonov.wordpress.com/


Monday, August 27, 2012 3:27 PM

Yes the printers are already mapped.  Well here's the story, printers are mapped in the login script. 

For some reason, the default printer changes randomly, so what i'm trying to do is, select default printer name in a variable, remove all printer from the session, then remap printers and re-set default printer with the variable i took at the begining.

It's working fine, but for some reason, it will not run the command : Get-WMIObject Win32_Printer | where{$_.Network -eq 'true'} | foreach{$_.delete()} in the script...


Monday, August 27, 2012 3:28 PM

Is there a way to run a ps1 file in GGP?!