0

I have the following code.

$output_status = 0
if($output_status -eq 0){
   'All ok'
}
else{
    'Error'
}
'----------------------------------------------------------------------------'
'List of all printers'
'----------------------------------------------------------------------------'
$printer_list
'----------------------------------------------------------------------------'
'Driver versions for the printers'
'----------------------------------------------------------------------------'
$Drivers = Get-PrinterDriver | Select-Object Name,@{n="DriverVersion";e={ $ver = $_.DriverVersion;(3..0 | ForEach-Object { ($ver -shr ($_ * 16)) -band 0xffff }) -join '.'}}
$Drivers
'----------------------------------------------------------------------------'
if($datas -ne $null){
    'Print driver changed date'
    '----------------------------------------------------------------------------'
    $datas
    '----------------------------------------------------------------------------'
}
foreach($item4 in $printers){
    $queue1 = Get-PrintJob -PrinterName $item4
    if($queue1 -ne $null){
        '----------------------------------------------------------------------------'
        'Print queue for ' + $item4
        $queue1
        '----------------------------------------------------------------------------'
    }
}
exit $output_status

when I run the above script it shows the following output

All ok
----------------------------------------------------------------------------
List of all printers
----------------------------------------------------------------------------

Name                                                    DriverName                       PrinterStatus ComputerName
----                                                    ----------                       ------------- ------------
Microsoft XPS Document Writer                           Microsoft XPS Document Writer v4        Normal I-HYPERV    
Microsoft Print to PDF                                  Microsoft Print To PDF                  Normal I-HYPERV    
----------------------------------------------------------------------------
Driver versions for the printers
--------------------------------------------------------------------------------------------------------------------
Microsoft XPS Document Writer v4                                                                                   
Microsoft Print To PDF                                                                                             
Microsoft enhanced Point and Print compatibility driver                                                            
Microsoft enhanced Point and Print compatibility driver                                                            
----------------------------------------------------------------------------

but when I just select the following two lines

$Drivers = Get-PrinterDriver | Select-Object Name,@{n="DriverVersion";e={ $ver = $_.DriverVersion;(3..0 | ForEach-Object { ($ver -shr ($_ * 16)) -band 0xffff }) -join '.'}}
$Drivers

and run the selected lines I am getting the following output.

Name                                                    DriverVersion  
----                                                    -------------  
Microsoft XPS Document Writer v4                        10.0.17763.1   
Microsoft Print To PDF                                  10.0.17763.1   
Microsoft enhanced Point and Print compatibility driver 10.0.17763.1457
Microsoft enhanced Point and Print compatibility driver 10.0.17763.1457

so, my problem is when I run all script why don't I get DriverVersion I try many things but not any success.

Divyesh Jesadiya
  • 1,105
  • 4
  • 30
  • 68
  • 2
    `$Drivers` -> `$Drivers |Format-Table` – Mathias R. Jessen Nov 27 '20 at 12:11
  • 1
    Yes working thank you – Divyesh Jesadiya Nov 27 '20 at 13:33
  • Your problem is a _display_ problem: If the first output object implicitly triggers tabular (`Format-Table`) formatting, its properties alone determine the table columns, even if subsequent objects (other than strings and primitive .NET types) have different properties. You can force given output to show all properties by piping to `Out-Host` or a `Format-*` cmdlet such as `Format-Table`, but that will prevent you from capturing or redirecting the output - see [this answer](https://stackoverflow.com/a/50416448/45375) to the linked duplicate. – mklement0 Nov 27 '20 at 13:35

0 Answers0