?
Solved

Powershell script - map a networked printer onto a remote PC

Posted on 2012-09-03
4
Medium Priority
?
1,137 Views
Last Modified: 2012-09-14
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!"}
0
Comment
Question by:alienvoice
  • 2
4 Comments
 
LVL 3

Expert Comment

by:Akulsh
ID: 38362644
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.
0
 
LVL 6

Expert Comment

by:slidingfox
ID: 38362774
is the IP Address an array?

if so, try changing your if statement to read

if ($ipinfo.IPAddress -contains "172.16.13.73")
0
 
LVL 15

Accepted Solution

by:
alienvoice earned 0 total points
ID: 38381634
Turns out WMI can't be used the way I intended. Switch to using vb script instead.
0
 
LVL 15

Author Closing Comment

by:alienvoice
ID: 38398098
Turns out WMI can't be used the way I intended. Switch to using vb script instead.
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question