Link to home
Start Free TrialLog in
Avatar of alienvoice
alienvoiceFlag for Australia

asked on

Powershell script - map a networked printer onto a remote PC

Hi everyone,

Below is a script I have be writing, (with some help from Experts here), to get the IP of a remote PC. Confirm it and based on the confirmation of the IP, I am trying to install a printer, (that is shared on a print server), on the remote PC.

The script completes but no printer is added on the remote PC.

Any ideas?

$strComputerID = "pc.domain.com"
$Ipinfo = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=TRUE and DHCPEnabled=TRUE" -comp $strComputerID
$IPinfo.IPAddress
$PrinterPath = "\\prd-printserv\ams-L3-TOS6550C-P1-BW"
$net = new-Object -com WScript.Network

if($Ipinfo.IPAddress -eq "172.16.13.73"){$net.AddWindowsPrinterConnection($PrinterPath)}
else{"Wrong IP, no printer for you!"}
Avatar of Akulsh
Akulsh
Flag of India image

Your $PrinterPath = "\\Server\PrintShare" line has a very odd and long name for PrintShare.

Have you tried a short name of PrintShare just for testing? I presume your Server name is correct.
Avatar of slidingfox
is the IP Address an array?

if so, try changing your if statement to read

if ($ipinfo.IPAddress -contains "172.16.13.73")
ASKER CERTIFIED SOLUTION
Avatar of alienvoice
alienvoice
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alienvoice

ASKER

Turns out WMI can't be used the way I intended. Switch to using vb script instead.