'Add specific printer to multiple servers
I am new to powershell and would like to create a tool to add a single printer to multiple servers. Here is my code so far:
$printer = read-host "Please enter the printer name"
$ip = read-host "Please enter the printer IP"
foreach ($server in @("NPARTS20SVR",
                      "NPARTS21SVR",
                      "NPARTS22SVR",
                      "NPARTS23SVR",
                      "NPARTS24SVR")) {
    
      Add-PrinterPort -ComputerName $server -Name $ip -PrinterHostAddress $ip
      Add-Printer -ComputerName $server -ConnectionName $printer -PortName $ip -Comment $ip
   
}
Here is the error I am getting:
Add-PrinterPort : An error occurred while performing the specified operation.  See the error details for more
information.
At \\gogo\Software\HELP\NewBuild\PreDomain\Sham scripts\AddPrinterSVR.ps1:14 char:7
+       Add-PrinterPort -ComputerName $server -Name $ip -PrinterHostAdd ...
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (MSFT_PrinterPortTasks:ROOT/StandardCimv2/MSFT_PrinterPortTasks) [Add-Prin
   terPort], CimException
    + FullyQualifiedErrorId : HRESULT 0x8007011b,Add-PrinterPort
Add-Printer : Parameter set cannot be resolved using the specified named parameters.
At \\gogo\Software\HELP\NewBuild\PreDomain\Sham scripts\AddPrinterSVR.ps1:15 char:7
+       Add-Printer -ComputerName $server -ConnectionName $printer -Por ...
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Add-Printer], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Add-Printer
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
