Аудит принтеров 64 бит
Я запускаю следующий скрипт для получения отчета об установленных принтерах:
https://community.spiceworks.com/scripts/show/2186-export-printer-information-to-spreadsheet?page=1
Однако, когда скрипт работает, он ищет 64-битный драйвер, извлекает его, копирует в вывод Excel, а затем сканирует 32-битный и перезаписывает исходный 64-битный.
Я безуспешно пытался найти решение:
# Get printer information
ForEach ($PrintServer in $PrintServers)
{ Write-Verbose "$(Get-Date): Working on $PrintServer..."
$Printers = Get-WmiObject Win32_Printer -ComputerName $PrintServer
ForEach ($Printer in $Printers)
{
If ($Printer.Name -notlike "Microsoft XPS*")
{
$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, 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
}
}
$Sheet.Cells.Item($intRow, 6) = $Printer.DriverName
$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, 9) = $Printer.Shared
$Sheet.Cells.Item($intRow, 10) = $Printer.ShareName
$Sheet.Cells.Item($intRow, 11) = Split-Path
$Driver.SupportedPlatform -Leaf
$intRow ++
}
**************************
Это не помогает, может кто-нибудь подсказать, как извлечь 64-битный драйвер и направить его в электронную таблицу.
1 ответ
Вы можете создать переменную для отслеживания индекса столбца, аналогично $ intRow, но сделать ее локальной для цикла get printers. Затем просто увеличивайте его каждый раз, когда вставляете в электронную таблицу. Код ниже. Возможно, вы захотите переместить всю информацию о драйвере в конец строки, чтобы ваши столбцы выстроились в линию.
# Get printer information
ForEach ($PrintServer in $PrintServers)
{ Write-Verbose "$(Get-Date): Working on $PrintServer..."
$Printers = Get-WmiObject Win32_Printer -ComputerName $PrintServer
ForEach ($Printer in $Printers)
{
If ($Printer.Name -notlike "Microsoft XPS*")
{
$intCol = 1 #Declare column index here
$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, $intCol++) = $PrintServer $Sheet.Cells.Item($intRow, 2) = $Printer.Name
$Sheet.Cells.Item($intRow, $intCol++) = $Printer.Location
$Sheet.Cells.Item($intRow, $intCol++) = $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, $intCol++) = $Port.HostAddress
}
}
$Sheet.Cells.Item($intRow, $intCol++) = $Printer.DriverName
$Sheet.Cells.Item($intRow, $intCol++) = (Get-ItemProperty ($Driver.DriverPath.Replace("$Drive`:","\\$PrintServer\$Drive`$"))).VersionInfo.ProductVersion
$Sheet.Cells.Item($intRow, $intCol++) = Split-Path $Driver.DriverPath -Leaf
$Sheet.Cells.Item($intRow, $intCol++) = $Printer.Shared
$Sheet.Cells.Item($intRow, $intCol++) = $Printer.ShareName
$Sheet.Cells.Item($intRow, $intCol++) = Split-Path
$Driver.SupportedPlatform -Leaf
$intRow ++
}
**************************