May 27, 2013

Just thought I'd post my powershell script on how to install local printers on remote workstations from a text file.  I know most people use print server nowadays, but there's always one or two that will find this information useful.  In a later post, I'll cover the process on how to make a printer settings file that I use here.


Function AddPrinterDriver($targetComputer, $driverSource, $driverINF, $driverName) {
    $model =  $driverSource.Substring($driverSource.LastIndexOf("\")+1)
    $driverDestination = "\\$targetComputer\c$\temp\printers\$model"
    $psexecPath = "C:\Users\Public\PSTools\PsExec.exe"

    "Driver Destination: " + $driverDestination
    "Driver Source: $driverSource\"
    #Copy folder to remote computer
    if(Test-Path "$driverDestination")
    {
        #code if driver is already there
    } else {       
        if(test-path "$driverSource"){
            Copy-Item "$driverSource\" "$driverDestination" -recurse
        } else {
            "$driverSource does not exist"
        exit
        }

    }
   
   
    # install printer using INF file,  /u -  /m - model /f - file   
    $driverInstallcommand =  "C:\WINDOWS\system32\rundll32.exe printui.dll,PrintUIEntry /ia /u /m ""$driverName"" /f ""$driverDestination\$driverINF"""   
    $installCommand = "\\$targetComputer " + $driverInstallcommand
   
    start-process $psexecPath -ArgumentList $installCommand -NoNewWindow
    start-sleep -s 15

    #Remove folder recursively
    #Remove-Item -Recurse -Force $driverDestination
}

function CreatePrinterPort ($TargetComputer, $PortName, $HostAddress) {
    $port = ([WMICLASS]"\\$TargetComputer\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()
    $port.Name=$PortName
    $port.SNMPEnabled=$false
    $port.Protocol=1
    $port.HostAddress=$HostAddress
    $port.Put()
}

function CreatePrinter ($TargetComputer, $DriverName, $PortName, $Location, $Comment) {
    $print = ([WMICLASS]"\\$TargetComputer\ROOT\cimv2:Win32_Printer").createInstance()
   
    $print.PortName = $PortName
    $print.Shared = $false   
   
    $print.drivername = $DriverName
    $print.Location = $Location
    $print.Comment = $Comment
    $print.DeviceID = $PortName
    
    $print.Put()     
}

function setPrinterSettings($targetComputer, $portName, $binFile, $psExecPath){

    #Add Binfile Settings to Printer
   
    Copy-Item $binFile "\\$targetComputer\c$\temp\"
    $newBin = "\\$targetComputer\c$\temp\" + $portName + ".bin"

    $PrinterSettingsCommand =  "C:\WINDOWS\system32\rundll32.exe printui.dll,PrintUIEntry /Sr /n ""$portName"" /a ""$newBin"" g d"
    $installCommand = "\\$targetComputer " + $PrinterSettingsCommand
   
    $installCommand
    start-process $psexecPath -ArgumentList $installCommand
   
}

$computerList = Get-Content "c:\temp\PrinterInstallList.txt"

$driverINF = "hpc4700b.inf"
$psExecPath = "C:\Users\Public\PSTools\PsExec.exe"
$PortName = "200WELL02P04"
$DriverName = "HP Color LaserJet 4700 PCL 5c"
$driverSource = "\\dtftp\e$\PRINTERS\_Script Installs\200 Wellington\HP4700"
$binFile = "\\dtftp\e$\PRINTERS\_Script Installs\200 Wellington\200well02p04.bin"



Foreach($targetComputer in $computerList)
{   
    #Test if Online
    if(Test-Connection -ComputerName $targetComputer -Count 1 -ErrorAction SilentlyContinue)
    {
        #Test if printer is installed
        $colItems = get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername $targetComputer | where {$_.name -eq $portName}
        if($colItems)
        {
            "$targetComputer,Already Installed"
        }else{
            AddPrinterDriver -targetComputer $targetComputer -driverSource $driverSource -driverINF $driverINF -driverName $driverName
            CreatePrinterPort -TargetComputer $targetComputer -HostAddress "$PortName.printers.toronto.ca" -PortName $PortName
            CreatePrinter -TargetComputer $targetComputer -PortName $PortName -DriverName $DriverName
            setPrinterSettings -targetComputer $targetComputer -portName $portName -binFile $binFile -psExecPath $psExecpath
            "$targetComputer, Installed"
        }

    } else {
        "$targetComputer,NotOnline"
    }
}

April 20, 2012

Just another day at the City...

Love how it can take over a month to push out a flash update because it needs to be tested in an organization that does not have any flash based applications.  Something doesn't add up here.

February 17, 2012

Been at work developing mobile applications. I have a blackbelt workout tracker that's been posted to the blackberry market!

http://appworld.blackberry.com/webstore/content/84066/?lang=EN

August 13, 2008

Almost a year between posts. Not quite though.

I'm a systems administrator now! YAY!

August 22, 2007

For today's post I'm just going to link to another blog.

http://www.bramaleainsurgent.com/police-provocateurs-at-summit/

August 13, 2007

1,010 Posts, last published on Feb 22, 2007

Yes, it's been a long time coming...over half a year, but I am back and better than ever! (just no redesign yet). What have I been up to? Well lets see...in the time since February, I've been to Vegas, England, Ireland, Germany, a few cottages, Atlantic City, Philadelphia, Niagara more times than I care to acknowledge, a (under-20) world cup final, Toronto FC game, 3 Blue Jay games, one job interview (for which I turned down the position), sold a focus and bought a Mazda 3. That's about 6 months of posts right there!

Highlight of all this? I'd have to say going to Berlin was pretty cool, but buying my new Mazda3 Sport GT was far and above my highlight. Got it in Electric Blue, it's so sweet! One day I'll post a picture of it...one day.