Hi Guys,
I have this script that queries remote machines to get all java version installed.
There is one query for 32 bits and another one for 64 bits as i need them to be separated in my csv.
It works absolutely fine if a machine has one 32 bits version and/or a 64 bits too.
However, if the machine has more than one 32 bits or 64 bits, the wmi query outputs 2 lines, and in my csv i get System.object.
Current CSV output:
Computer Name Statut Java 32 bits version Java 64 bits version GVA-GUEST-08 Online Java 8 Update 91 GVA-GUEST-09 Online System.Object[] Java 8 Update 40 (64-bit)
Sorry for the Where-Object verylong lines, piping was the only way i found to add multiple conditions.
Any help ?
My code:
$ComputerList = Read-Host -Prompt 'Enter path to computer list' $ComputerName = Get-Content $ComputerList Function Get-JavaVersion{ Foreach ($C in $ComputerName) { If (-not (Test-Connection -cn $C -quiet -Count 1)){ $OffHashTable=[ordered]@{ 'Computer Name'=$C 'Statut'='Offline' } New-Object PSObject -Property $OffHashTable } Else { $Java32 = gwmi -cn $C Win32_Product | ? Name -Like "Java*Update*" | ? Name -NotLike "*64*" | ? Name -NotLike "*Auto*" | ? Name -NotLike "*Development*" -ErrorAction SilentlyContinue $Java64 = gwmi -cn $C Win32_Product | ? Name -Like "Java*Update*64*" | ? Name -NotLike "*Auto*"| ? Name -NotLike "*Development*" -ErrorAction SilentlyContinue $OnHashTable=[ordered]@{ 'Computer Name'=$C 'Statut'='Online' 'Java 32 bits version'=$Java32.caption 'Java 64 bits version'=$Java64.caption } New-Object PSObject -Property $OnHashTable } } } Get-JavaVersion | Export-Csv C:\Javaversion.csv -NoTypeInformation