PoshCode Archive  Artifact [6b1b20e8d5]

Artifact 6b1b20e8d5326b983fc52881f98b7fcafba324a7c331a0892a91ded7e0ecc2dd:

  • File Get-PrinterInfo.ps1 — part of check-in [7c4beab5f8] at 2018-06-10 13:32:52 on branch trunk — Creates a backup of the configuration of the network printers on a server or computer and exports it to a csv file. (user: Ryan Tranchilla size: 1928)

# encoding: utf-8
# api: powershell
# title: Get-PrinterInfo
# description: Creates a backup of the configuration of the network printers on a server or computer and exports it to a csv file.
# version: 0.1
# type: class
# author: Ryan Tranchilla
# license: CC0
# x-poshcode-id: 3916
# x-derived-from-id: 5754
# x-archived: 2015-05-11T08:32:26
# x-published: 2015-01-25T07:34:00
#
#
$strComputer = "PrinterName"
$Ports = get-wmiobject -class "win32_tcpipprinterport" -namespace "root\CIMV2" -computername $strComputer
$Printers = get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername $strComputer
$ports | Select-Object Name,Hostaddress | Set-Variable port
$Printers | Select-Object Name,PortName,DriverName,location,Description | Set-Variable print
$num = 0
$hash = @{}
do {
$hash.Add($port.name[$num], $port.hostaddress[$num])
$num = $num + 1
} until ($num -eq $ports.Count)

# Creates Table
$table = New-Object system.Data.DataTable “$PrinterInfo”
$colName = New-Object system.Data.DataColumn PrinterName,([string])
$colIP = New-Object system.Data.DataColumn IP,([string])
$colDrive = New-Object system.Data.DataColumn DriverName,([string])
$colLoc = New-Object system.Data.DataColumn location,([string])
$colDesc = New-Object system.Data.DataColumn Description,([string])
$table.columns.add($colName)
$table.columns.add($colIP)
$table.columns.add($colDrive)
$table.columns.add($colLoc)
$table.columns.add($colDesc)
$num = 0
Do {
$row = $table.NewRow()
$row.PrinterName = $printers.name[$num]
$row.IP = $hash.get_item($printers.PortName[$num])
$row.DriverName = $printers.drivername[$num]
$row.Location = $printers.Location[$num]
$row.Description = $printers.Description[$num]
$table.Rows.Add($row)
$num = $num + 1
} until ($num -eq $printers.Count)

$table | Select-Object PrinterName,IP,DriverName,Location,Description | Export-Csv C:\Printers.csv