Set bulk number of printers not shared

Welcome Forums General PowerShell Q&A Set bulk number of printers not shared

Viewing 4 reply threads
  • Author
    Posts
    • #272350
      Participant
      Topics: 12
      Replies: 16
      Points: 182
      Rank: Participant

      hello everyone,

      I have Windows server 2012R2 printer server with many printers shared on the network.

      using Set-Printer -name "Name" -shared $true / $false I am able to change one printer’s configuration.

      what i’m looking for is how to get .txt file’s content (each printer name in a separate line of course) and apply configuration for all.

      I’ve spent many hours to figure it out but didn’t success unfortunately.

      • This topic was modified 2 weeks, 1 day ago by Atx750k.
    • #272371
      Participant
      Topics: 5
      Replies: 177
      Points: 686
      Helping Hand
      Rank: Major Contributor

      You basically just need to get the contents of the file then loop over each printer in that file to run your command.  Fortunately, PowerShell has two cmdlets that will help with that Get-Content and ForEach-Object.

      In the ForEach-Object loop $_ is an alias for $PSItem which is the current object in the loop.  In your case a string with the printer name.

    • #272374
      Participant
      Topics: 5
      Replies: 341
      Points: 586
      Helping Hand
      Rank: Major Contributor
    • #272383
      Participant
      Topics: 12
      Replies: 16
      Points: 182
      Rank: Participant

      Guys, I really appreciate your help, that saved me a lot of time.

      works great. thanks.

    • #272446
      Participant
      Topics: 4
      Replies: 98
      Points: 442
      Helping Hand
      Rank: Contributor

      The “-Name” Parameter is capable of accepting multiple values as indicated by the typecasting [string[]]. With that said, you don’tneed to do a Foreach. You can just provide the entire list as an argument to the -Name parameter.

      • This reply was modified 2 weeks, 1 day ago by Logan Boydell (LBo). Reason: fixed code formatting
Viewing 4 reply threads
  • You must be logged in to reply to this topic.