0

I'm running the following script to get a report on installed printers :

https://community.spiceworks.com/scripts/show/2186-export-printer-information-to-spreadsheet?page=1

However when the script is working it scans for the 64 bit driver retrieves it, copy's to the excel output and then scans for the 32 bit and overwrites the original 64bit.

I have tried unsuccessfully to come up with a solution :

# 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 ++



       }

**************************

This fails,can someone suggest how to retrieve the 64bit driver also and pipe it into the spreadsheet.

JJJJNR
  • 870
  • 6
  • 20
  • 32

1 Answers1

0

You can create a variable to keep track of your column index, similar to $intRow, but make it local to the get printers loop. Then just increment it every time you insert into the spreadsheet. The code is below. You'll probably want to move all the driver information to the end of the row so your columns line up.

# 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 ++



       }

**************************
Atoadaso
  • 101
  • Thanks, $intCol = 1 #Declare column index here $Drivers = Get-WmiObject Win32_PrinterDriver -Filter "__path like '%$($Printer.DriverName)%'" -ComputerName $Printserver But the script fails at this point. – JJJJNR May 09 '16 at 08:42