Created
May 31, 2022 04:54
-
-
Save stevesbrain/d2bc7f1cd406159d6293d0668557a419 to your computer and use it in GitHub Desktop.
Outputs an excel sheet detailing printers, drivers, share name, server, IP, etc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param ( | |
[string]$Printservers = "SERVERNAME.domain" | |
) | |
# Create new Excel workbook | |
cls | |
$Excel = New-Object -ComObject Excel.Application | |
$Excel.Visible = $True | |
$Excel = $Excel.Workbooks.Add() | |
$Sheet = $Excel.Worksheets.Item(1) | |
$Sheet.Name = "Printer Inventory" | |
#====================================================== | |
$Sheet.Cells.Item(1,1) = "Print Server" | |
$Sheet.Cells.Item(1,2) = "Printer Name" | |
$Sheet.Cells.Item(1,3) = "Location" | |
$Sheet.Cells.Item(1,4) = "Comment" | |
$Sheet.Cells.Item(1,5) = "IP Address" | |
$Sheet.Cells.Item(1,6) = "Driver Name" | |
$Sheet.Cells.Item(1,7) = "Driver Version" | |
$Sheet.Cells.Item(1,8) = "Driver" | |
$Sheet.Cells.Item(1,9) = "Shared" | |
$Sheet.Cells.Item(1,10) = "Share Name" | |
#======================================================= | |
$intRow = 2 | |
$WorkBook = $Sheet.UsedRange | |
$WorkBook.Interior.ColorIndex = 40 | |
$WorkBook.Font.ColorIndex = 11 | |
$WorkBook.Font.Bold = $True | |
#======================================================= | |
# Get printer information | |
ForEach ($Printserver in $Printservers) | |
{ $Printers = Get-WmiObject Win32_Printer -ComputerName $Printserver | |
ForEach ($Printer in $Printers) | |
{ | |
if ($Printer.Name -notlike "Microsoft XPS*") | |
{ | |
$Sheet.Cells.Item($intRow, 1) = $Printserver | |
$Sheet.Cells.Item($intRow, 2) = $Printer.Name | |
$Sheet.Cells.Item($intRow, 3) = $Printer.Location | |
$Sheet.Cells.Item($intRow, 4) = $Printer.Comment | |
If ($Printer.PortName -notlike "*\*") | |
{ $Ports = Get-WmiObject Win32_TcpIpPrinterPort -Filter "name = '$($Printer.Portname)'" -ComputerName $Printserver | |
ForEach ($Port in $Ports) | |
{ | |
$Sheet.Cells.Item($intRow, 5) = $Port.HostAddress | |
} | |
} | |
#################### | |
$Drivers = Get-WmiObject Win32_PrinterDriver -Filter "__path like '%$($Printer.DriverName)%'" -ComputerName $Printserver | |
ForEach ($Driver in $Drivers) | |
{ | |
$Drive = $Driver.DriverPath.Substring(0,1) | |
$Sheet.Cells.Item($intRow, 7) = (Get-ItemProperty ($Driver.DriverPath.Replace("$Drive`:","\\$PrintServer\$Drive`$"))).VersionInfo.ProductVersion | |
$Sheet.Cells.Item($intRow,8) = Split-Path $Driver.DriverPath -Leaf | |
} | |
#################### | |
$Sheet.Cells.Item($intRow, 6) = $Printer.DriverName | |
$Sheet.Cells.Item($intRow, 9) = $Printer.Shared | |
$Sheet.Cells.Item($intRow, 10) = $Printer.ShareName | |
$intRow ++ | |
} | |
} | |
$WorkBook.EntireColumn.AutoFit() | Out-Null | |
} | |
$intRow ++ | |
$Sheet.Cells.Item($intRow,1) = "Printer inventory completed" | |
$Sheet.Cells.Item($intRow,1).Font.Bold = $True | |
$Sheet.Cells.Item($intRow,1).Interior.ColorIndex = 40 | |
$Sheet.Cells.Item($intRow,2).Interior.ColorIndex = 40 | |
## Source from https://community.spiceworks.com/topic/354692-export-a-list-of-printer-names-models-and-ip-addresses |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment