Set bulk number of printers not shared

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.

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.

$printerfile = ".\yourfile.txt" #path to your text file Get-Content -Path$printerfile |
ForEach-Object {
Set-Printer -Name $_ -Shared$true
}

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.

$printer = Get-Content -Path \\path\to\printlist.txt foreach ($p in $printer){ Write-Verbose "Printer$p" -Verbose
Set-Printer -Name $p -Shared$false
}


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

works great. thanks.

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.

$printerFile = Get-Content ".\yourFile.txt" #path to text file Set-Printer -Name$printerFile -Shared:\$false