Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AddWindowsPrinterConnection

558 views
Skip to first unread message

greatbarrier86

unread,
Mar 23, 2008, 2:44:00 PM3/23/08
to
Hi,

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

Shay Levi

unread,
Mar 24, 2008, 5:00:19 AM3/24/08
to

Hi 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

Shay Levi

unread,
Mar 24, 2008, 8:50:27 AM3/24/08
to

WMI one-liners using [wmiclass] type accelerator:

# for local use
([wmiclass]"Win32_Printer").AddPrinterConnection("\\ServerName\PrinterName")

# for remote computers
([wmiclass]"\\$computer\root\cimv2:Win32_Printer").AddPrinterConnection("\\ServerName\PrinterName")

greatbarrier86

unread,
Mar 24, 2008, 3:29:01 PM3/24/08
to
Shay,

1. Which do you recommend? WSH or WMI?
2. Can most methods be invoked in the wmi manner? eg:
AddNetworkConnection...etc

Shay Levi

unread,
Mar 24, 2008, 3:39:34 PM3/24/08
to

WMI can run from a central location against remote computers, WSH can't.
It depends on your needs. In terms of performace, WMI calls are slower then
WSH.

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

> Shay,

greatbarrier86

unread,
Mar 24, 2008, 3:54:02 PM3/24/08
to
I'm only going to run it on the local computer so i wont use WMI. Also, is
using WSH the appropriate way to do this. I've also seen stuff related to
like [system.assembly....] I dont particularly understand it. Do you know
what i am referring to? I think it's related to .net

Shay Levi

unread,
Mar 24, 2008, 4:18:06 PM3/24/08
to

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?

0 new messages