Author Posts

April 7, 2016 at 6:11 am

I am a noob at PowerShell and I am looking for help finishing this script. I am stuck on the Create Printer Function. I want to install a printer via TCP IP. No print server in our environment. Later I want to add some choice menus, This would allow users on our network to come in from different offices, choose locations and choose printer closet to them, but for now getting this test installed would be great. Here is what I got so far

$PrinterIP = “”
$PrinterPort = “9100”
$PrinterPortName = “IP_” + $PrinterIP
$DriverName = “Ricoh Aficio MP C6000 PS”
$DriverPath = “\\bh-miworks-srv2\PrintDrivers\Ricoh MP c6501 e7200 Dockside Color\Win 10 PS\English\Prntdrvr\Ps_drvr\Win_2K_XP_VISTA”
$DriverInf = “\\bh-miworks-srv2\PrintDrivers\Ricoh MP c6501 e7200 Dockside Color\Win 10 PS\English\Prntdrvr\Ps_drvr\Win_2K_XP_VISTA\oemsetup.inf”
$PrinterCaption = “BH DockSide Color”

Function CreatePrinterPort {
param ($PrinterIP, $PrinterPort, $PrinterPortName, $ComputerName)
$wmi = [wmiclass]”\\$ComputerName\root\cimv2:win32_tcpipPrinterPort”
$wmi.psbase.scope.options.enablePrivileges = $true
$Port = $wmi.createInstance()
$ = $
$Port.hostAddress = $
$Port.portNumber = $1900
$Port.SNMPEnabled = $false
$Port.Protocol = 1

Function InstallPrinterDriver {
Param ($DriverName, $DriverPath, $DriverInf, $ComputerName)
$wmi = [wmiclass]”\\$ComputerName\Root\cimv2:Win32_PrinterDriver”
$wmi.psbase.scope.options.enablePrivileges = $true
$wmi.psbase.Scope.Options.Impersonation = `
$Driver = $wmi.CreateInstance()
$Driver.Name = $"Ricoh Aficio MP C6000 PS"
$Driver.DriverPath = $\\bh-miworks-srv2\PrintDrivers\Ricoh MP c6501 e7200 Dockside Color\Win 10 PS\English\Prntdrvr\Ps_drvr\Win_2K_XP_VISTA
$Driver.InfName = $\\bh-miworks-srv2\PrintDrivers\Ricoh MP c6501 e7200 Dockside Color\Win 10 PS\English\Prntdrvr\Ps_drvr\Win_2K_XP_VISTA\oemsetup.inf

Function CreatePrinter {
param ($PrinterCaption, $PrinterPortName, $DriverName, $ComputerName)
$wmi = ([WMIClass]”\\$ComputerName\Root\cimv2:Win32_Printer”)
$Printer = $wmi.CreateInstance()
$Printer.Caption = $"BH DockSide Color"
$Printer.DriverName = $"Ricoh Aficio MP C6000 PS"
$Printer.PortName = $
$Printer.DeviceID = $"DockSide Color"

any help or suggestions would be appreciated.

PS sorry if my code is not properly formatted. if someone has a document or example I will be sure to follow next time.

April 7, 2016 at 6:48 am

I see this is the same code as posted by Kris Powell.

That script is not working for you?

April 7, 2016 at 7:15 am

It is, I changes the variables to match our environment and printers, so far the error I get is this:

At C:\Users\christnerw\Desktop\printer test.ps1:36 char:24
+ Function CreatePrinter {
+                        ~
Missing closing '}' in statement block.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingEndCurlyBrace

If i am missing a "}" I haven't found it yet.


April 7, 2016 at 7:27 am

Put the closing curly brace after $Printer.Put()

April 7, 2016 at 7:40 am

Cool no Error, But no Printer installed either.

I am closer now. I can't believe I didn't see that. Wow I am a Noob

April 7, 2016 at 7:51 am

Which OS are you using? From Windows 8 and higher you have add-printer available. 🙂

April 8, 2016 at 5:53 am

Windows 7 SP1
The orgional script calls for the

### ComputerList Option 1 ###
# $ComputerList = @(“lana”, “lisaburger”)

### ComputerList Option 2 ###
# $ComputerList = @()
# Import-Csv “C:\Temp\ComputersThatNeedPrinters.csv” | `
# % {$ComputerList += $_.Computer}

and the

 foreach ($computer in $ComputerList) {
CreatePrinterPort -PrinterIP $PrinterIP -PrinterPort $PrinterPort `
-PrinterPortName $PrinterPortName -ComputerName $computer
InstallPrinterDriver -DriverName $DriverName -DriverPath `
$DriverPath -DriverInf $DriverInf -ComputerName $computer
CreatePrinter -PrinterPortName $PrinterPortName -DriverName `
$DriverName -PrinterCaption $PrinterCaption -ComputerName $computer

I wonder if I need to do this as well. though I don't see how the Printer is not installing . Oh well back to the drawing board!

April 8, 2016 at 5:55 am

Yeah, you need to "do" something with the functions. The functions declare only code; they don't do anything until you load them into memory, and execute them. That is what the code is doing what you showed.

April 8, 2016 at 9:45 am

Ok I will look into "do" I appreciate your insights. I have learned a lot so far. I you can point me in the right direction that would be awesome. however google is my friend.

thanks again

April 8, 2016 at 2:11 pm

You were saying that you are new to PowerShell. I would recommend you to read these two books:

In these books you will learn what functions are and how you use them. I could do a whole story about functions and how they have to be used, but I think I'm better off to give you two good resources.

April 11, 2016 at 4:27 am

Thanks I will definitely check out these books today!