PoshCode Archive  Artifact [4a281c9017]

Artifact 4a281c9017b0725c457587fdc2bfbd301800bf80c62a3977acee75e56557ff0d:

  • File Get-PrinterInfo.ps1 — part of check-in [2037430cee] at 2018-06-10 14:00:41 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: 1958)

# 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: 5754
# x-archived: 2015-10-25T07:55:42
# x-published: 2015-02-25T09:39:00
#
#
$strComputer = "ComputerName"
$Ports = get-wmiobject -class "win32_tcpipprinterport" -namespace "root\CIMV2" -computername $strComputer -EnableAllPrivileges
$Printers = get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername $strComputer -EnableAllPrivileges
$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[$num].name, $port[$num].hostaddress)
$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[$num].name
$row.IP = $hash.get_item($printers[$num].PortName)
$row.DriverName = $printers[$num].drivername
$row.Location = $printers[$num].Location[$num]
$row.Description = $printers[$num].Description
$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 -NoType