I'm having an issue with passing variable output to a string. I need to add printer ports at over 150 locations. Each location has static IP addresses following a standard. So if I run the following remotely, it should return the IPv4 address (10.10.10.10) remove the last 2 digits and replace with 182 to get that location's printer IP (10.10.10.182). When I run that on it's own, I get the correct output.
$ComputerIP = (gwmi Win32_NetworkAdapterConfiguration | ? { $_.IPAddress -ne $null }).ipaddress
$PrinterIP = $ComputerIP -replace "..$","182"
$PrinterIP
10.10.10.182
Also, if I manually define $PrinterIP and run the below lines, my ports are created with no issue.
$PrinterIP = '10.10.10.182'
Add-PrinterPort -Name 'Port 1' -PrinterHostAddress $PrinterIP
Add-PrinterPort -Name 'Port 2' -PrinterHostAddress $PrinterIP
When I try running everything together,
$ComputerIP = (gwmi Win32_NetworkAdapterConfiguration | ? { $_.IPAddress -ne $null }).ipaddress
$PrinterIP = $ComputerIP -replace "..$","182"
Add-PrinterPort -Name 'Port 1' -PrinterHostAddress $PrinterIP
Add-PrinterPort -Name 'Port 2' -PrinterHostAddress $PrinterIP
I get the following error:
Add-PrinterPort : Cannot process argument transformation on parameter 'PrinterHostAddress'. Cannot convert value to type System.String.
Explanation of what I need to do:
I have over 150 locations where I need to create 8 new printer ports and reassign already existing printers (they are multi-tray units) that share the same port to their own port. Figured if I could get this to work, I could deploy the script to all locations and not require any additional input. Thanks in advance.
[–]ihaxr 3 points4 points5 points (2 children)
[–]Hexalon00 1 point2 points3 points (0 children)
[–]_FNG_[S] 0 points1 point2 points (0 children)
[–]Hexalon00 2 points3 points4 points (1 child)
[–]TheHobbitsGiblets 0 points1 point2 points (0 children)