1

I am attempting to export the installed version of Chrome for workstations on our network. I have put together the following script but am running into an issue with an error exporting to CSV. Any suggestions would be greatly appreciated.

Select-Object : Cannot convert System.Diagnostics.FileVersionInfo to one of the following types {System.String, System.Management.Automation.ScriptBlock}.
At line:22 char:14
            Select-Object $computer, $Version | export-csv -Path c:\ ...
     CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupportedException
     FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand

$computerlist = get-content C:\temp\computerlist.txt
foreach ($computer in $computerlist){
    $test = 1
    Write-Host "Testing connection to $computer..." -ForegroundColor Magenta
    Try{
        Test-Connection -Count 1 -ComputerName $computer -ErrorAction Stop | out-null
        Write-Host "Connected!" -ForegroundColor Green
        }
    Catch{
        Write-Host "Could not connect to $computer" -BackgroundColor Red -ForegroundColor Black
        $test = 0
        $computer | out-file c:\temp\badlist.txt    
        }
    If ($test -eq 1){
        ForEach($computer in $computerlist){
            $computer = $computer 
             $Version = (Get-Item (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe').'(Default)').VersionInfo
             "$computer - $Version"
             Out-String -InputObject $Version
             Select-Object $computer, $Version | export-csv -Path c:\temp\Chromeversion$($date)-PS.csv   -NoTypeInformation -Append 

1 Answers1

0

Select-Object $computer, $Version

doesn't work as intended, because Select-Object expects property names (or calculated properties) as the (positionally implied) -Property argument.

You're passing values, which are interpreted as names, and an instance of System.Diagnostics.FileVersionInfo (the type of the value stored in $Version) isn't accepted as a name, which is what the error message indicates.

To get what you want, construct a [pscustomobject] as follows:

[pscustomobject] @{ Computer = $computer; Version = $Version } | 
  Export-Csv -Path c:\temp\Chromeversion$($date)-PS.csv -NoTypeInformation -Append 
mklement0
  • 382,024
  • 64
  • 607
  • 775