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.
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