I'm not entirely sure how to do this in PowerShell. It's easy to do in
VBScript, but can someone offer me some assistance for this in PoSh?
Thanks.
Jason
Try using WSH or WMI. I offline so I can't test both methods but it should
do the job:
$net = new-object -com wscript.network
## 1. adds a network printer to an MS-DOS printer port, such as LPT1
$net.addPrinterConnection "LPT1", "\\Server\Print1"
- or -
## 2. add a remote windows-based printer connection
$net.addWindowsPrinterConnection "\\ServerName\PrinterName"
WMI:
## add a new printer connection to a remote computer
$computer = "."
$printer = gwmi -list | where {$_.name -eq "Win32_Printer"}
$printer.addPrinterConnection("\\ServerName\PrinterName")
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
# for local use
([wmiclass]"Win32_Printer").AddPrinterConnection("\\ServerName\PrinterName")
# for remote computers
([wmiclass]"\\$computer\root\cimv2:Win32_Printer").AddPrinterConnection("\\ServerName\PrinterName")
1. Which do you recommend? WSH or WMI?
2. Can most methods be invoked in the wmi manner? eg:
AddNetworkConnection...etc
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
> Shay,
There is one more method you might want to check, using printui.dll:
## Windows XP
http://support.microsoft.com/kb/314486/
## Windows 2000,2003
http://support.microsoft.com/kb/q189105/
As for system.assembly, it looks like .NET stuff, can you be more specific?