It works well for creating multiple printers really quick. It's a decent backup/DR method but an even better one would be using the PrintMig utility from Microsoft that will zip up queues, drivers, shares, etc. Then you can use it to dump everything back. I have is scripted out in a BAT file. I schedule a task to run the backup and RoboCopy it off to a remote location once a month on all out print servers. I'll try to attach my printer creating script. if you want more info on the PrintMig let me know. There is one field at the bottom you will want to modify and that's the variable that give the location of the CSV file $script:strCSVInputFile = "c:\temp\Printer_Input.csv" change it to whatever you want. #* FileName: Create_Print_Queue.ps1 #*============================================================================= #* Script Name: [Create_Print_Queue] #* Created: [3/25/10] #* Author: [Johnny Leuthard] #* Reqrmnts: [Drivers have to be on server. W2k-w2k8, win7, vista, W2K3] #* Keywords: [print queue port] #*============================================================================= #* Purpose: Create print queues from an input file (CSV) #*============================================================================= #*============================================================================= #* Beginning OF SCRIPT #*============================================================================= Clear-Host Write-Host #*============================================================================= #* FUNCTION LISTING #*============================================================================= #* Function: [Get_Info_From_CSV] #* Created: [3/28/10] #* Author: [Johnny Leuthard] #* Arguments: #*============================================================================= #* Purpose: Get info from an XLS file #*============================================================================= Function Get_Info_From_CSV { ## Create arrays to store info $script:strPrinterName = @() $script:strPortName = @() $script:strIPAddy = @() $script:strLocation = @() $script:strComment = @() $script:strPrintDriver = @() #Import data from a CSV ignoring any blank lines $strCSVdata = Import-Csv $strCSVInputFile | where {($_.Printername -ne "")} #Export data to XML #($strCSVdata | convertto-xml).save("\\dal1amspif006\d$\Admin\Tools\PowerShell_Scripts\TextFiles\test.xml") ## loop through and load up the arrays with the data from the CSV Foreach ($i in $strCSVdata) { $script:strPrinterName += $i.PrinterName $script:strPortName += $i.PortName $script:strIPAddy += $i.IPAddress $script:strLocation += $i.Location $script:strComment += $i.Comment $script:strPrintDriver += $i.PrintDriver } }#End Function #*============================================================================= #* FUNCTION LISTING #*============================================================================= #* Function: [Create_Port] #* Created: [3/25/10] #* Author: [Johnny Leuthard] #* Arguments: #*============================================================================= #* Purpose: Creat a TCP/IP port #*============================================================================= Function Create_Port { ##?? This works for both win7, 2008, w2k3. Write-Host ("`tCreating " + $strPrinterName.Count + " Printer Port's`t") -backgroundcolor black -ForegroundColor Green $objPort = [wmiclass]"Win32_TcpIpPrinterPort" $objPort.psbase.scope.options.EnablePrivileges = $true #Loop through and create each port For($i=0; $i -lt $strPortName.count; $i++) { $objNewPort = $objPort.CreateInstance() $objNewPort.psbase.scope.options.EnablePrivileges = $true $objNewPort.Name = $strPortName[$i] $objNewPort.HostAddress = $strIPAddy[$i] $objNewPort.Protocol = 1 #1=RAW (default) 2=LPR #$objNewPort.put() | Out-Null $objNewPort.put() } }#End Function #*============================================================================= #* FUNCTION LISTING #*============================================================================= #* Function: [Create_Queue] #* Created: [3/25/10] #* Author: [Johnny Leuthard] #* Arguments: #*============================================================================= #* Purpose: Create a print queue #*============================================================================= Function Create_Queue { ## ?? works for Win7, W2k8,W2K3 Write-Host ("`tCreating " + $strPrinterName.Count + " Printer's`t") -backgroundcolor black -ForegroundColor Green $objPrint = [WMICLASS]"Win32_Printer" $objPrint.psbase.scope.options.EnablePrivileges = $true ## Loop through and create each printer For($i=0; $i -lt $strPrinterName.count; $i++) { $objNewPrinter = $objPrint.createInstance() $objNewPrinter.DeviceID = $strPrinterName[$i] ## This is the printer name $objNewPrinter.DriverName = $strPrintDriver[$i] $objNewPrinter.PortName = $strPortName[$i] $objNewPrinter.Location = $strLocation[$i] $objNewPrinter.Comment = $strComment[$i] $objNewPrinter.Shared = $true $objNewPrinter.ShareName = $strPrinterName[$i] $objNewPrinter.KeepPrintedJobs = $false $objNewPrinter.Published = $true ## Publish in AD $objNewPrinter.DoCompleteFirst = $true ## Print spooled doc's first $objNewPrinter.Queued = $true ## Start printng after last page is spooled #$objNewPrinter.WorkOffline = $true ## Allows jobs to be sent to queue if printer is off-line #$objNewPrinter.Default = $false $objNewPrinter.Put() ## Add Security group ## Not completed yet } }#End Function #*============================================================================= #* SCRIPT BODY #*============================================================================= ## location of CSV file $script:strCSVInputFile = "C:\Temp\Printer_Input.csv" ## Call Get_Info_From_CSV Get_Info_From_CSV ## Call Create_Port Function Create_Port ## Call Create_Queue function Create_Queue #*============================================================================= #* END OF SCRIPT #*============================================================================= #*============================================================================= #* Notes: All text below here is commented out #*============================================================================= <# Driver names have to be exactly as they appear on a system. If you right click the printer, choose properties, it's exactly what is says for "Model" I just hilight that and copy and paste so i have it rught. Also all drivers have to be preinstalled on the server. Future revisions will hopefully grab them from a pool of drivers and install when needed but not right now Example of CSV file ======================= PrinterName,PortName,IPAddress,Location,Comment,PrintDriver Test_Printer_1,Test_Port_1,127.0.0.1,Nowhere_1,Comment 1,HP Laserjet 4300 PCL 6 Test_Printer_2,Test_Port_2,127.0.0.2,Nowhere_2,Comment 2,HP Laserjet 4300 PCL 6 #>
|