Skip to content

Instantly share code, notes, and snippets.

@nshores
Created January 11, 2019 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/a8b1a2bbc6a5885144bc1826f91602a2 to your computer and use it in GitHub Desktop.
Save nshores/a8b1a2bbc6a5885144bc1826f91602a2 to your computer and use it in GitHub Desktop.
printer_info
Param (
[string]$Printservers = "oldPrintServer"
)
# 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,2) = "Printer Name"
$Sheet.Cells.Item(1,5) = "IP Address"
#=======================================================
$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
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
}
}
$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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment