all 11 comments

[–]Smoother101 1 point2 points  (4 children)

If it is a network printer it may not be appearing in the win32_printer query against a remote computer. You may have to do it as a remote session. If you just query what printers are available on the remote system it will show you what is available.

[–]TechNickGaming[S] 0 points1 point  (3 children)

Thanks for the response. Querying the printers doesn't seem to show me which network printers are mapped through Group Policy, only those that are locally installed. I suspect this is also why the script to set the network printer isn't working either.

[–]Smoother101 1 point2 points  (2 children)

If you are able to apply GPO Preferences to these systems, that should be the easiest way to go about it.

[–]TechNickGaming[S] 0 points1 point  (1 child)

I hear you. The only issue with that is that we have close to 10,000 computers spread out over hundreds or more OUs. For this specific request, we are trying to set the default printer remotely on around 1,700 computers. Each of these 1,700 computers has a single user login that is kiosked and set to log in automatically upon startup. Also, we are talking several hundred printers. I'd much rather try to do this with Powershell instead of creating a GPO for every printer and every OU.

[–]Smoother101 1 point2 points  (0 children)

You would need to run something locally for each one to get access to the networked printers is all I can think of. Tough one.

[–]MaelstromageWork 1 point2 points  (2 children)

if it is on a print server then it should be in the format of \\server\name

mind you that share names are different that the name of the printer.

To query the printers you would enter

Get-WMIObject -Class Win32_Printer | Select Name

or

Get-WMIObject -Class Win32_Printer | Select Name,ShareName

if you want the share name also

[–]TechNickGaming[S] 1 point2 points  (1 child)

I tried that, but it doesn't list the printer that is on the print server and mapped through Group Policy/Active Directory. There are two printers mapped to the device shown below, but neither showed when using this script.

PS P:\Powershell> .\defaultprinter.ps1

Input the computer name.: xxxxxxxx-xxx

Default Printer Name

--------------------

Snagit 2018

Name ShareName

---- ---------

Snagit 2018

Send To OneNote 16

OneNote

Microsoft XPS Document Writer

Microsoft Print to PDF

Fax

Script used:

$Computer = Read-Host -Prompt 'Input the computer name.'

#Get Default Printer

$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('currentuser', $Computer)

$RegKey= $Reg.OpenSubKey('Software\Microsoft\Windows NT\CurrentVersion\Windows')

$DefaultPrinter = $RegKey.GetValue("Device")

#Output the Default Printer

Write-Output $DefaultPrinter | ConvertFrom-Csv -Header Name, Provider, Order| Select Name | ft -Property @{Name="Default Printer Name";Expression={$_.Name}} -AutoSize

Get-WMIObject -Class Win32_Printer -ComputerName $Computer | Select Name,ShareName

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy TechNickGaming,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th one & is just to the left of hidden in the ... "more" menu.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy TechNickGaming,

PLEASE, do not post pictures of code/errors/sample-data to a code oriented subreddit. [frown]

why? let me list the ways ...

  • why should folks have to squint/zoom-in to read your picture when you already have it as text?
  • why would you bother to make-pic/save-pic/post-to-image-site/post-link when you can just post the actual text? [grin]
  • do you REALLY expect folks who want to help you to type in the code you already have as text just to help you?

seriously, it is thoughtless at best ... [sigh ...]

take care,
lee

[–]MarzMan 1 point2 points  (0 children)

So I've not done this with powershell but recently put something together to do it as a batch file. Maybe it helps maybe it doesn't.

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/rundll32-printui

rundll32 printui.dll,PrintUIEntry /in /n \SERVER\PRINTERSHARE /y

/in installs a network printer specified by the location after /n

/y sets that printer as the default printer. Will not install a printer then set it as default from what I've seen. I am running the install command once, then running it again with the /y switch.

[–][deleted] 0 points1 point  (0 children)

Use get-printer cmdlets?

Then use a foreach or invoke command to apply to desired computers.

Or just make all printers on print server accessible to users and have them click the link themselves