0

I have a POWERSHELL script to check the presence of a predefined list of software: $SoftList = "Microsoft Visual C++ 2005 Redistributable","TotoInexistant","GIMP 2.6.11" define the list of software im looking to check.

i use a loop to compare the name of each software in the list above to resut of cmdlet as follow :

 foreach($i in $SoftList)
{
$x = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
select DisplayName, Publisher, InstallDate | Where-Object {$_.DisplayName -like $i} 
$x
$x.DisplayName >> ListOf.txt # or we can to display it on screen 
}

the probleme i'm facing is that the $x.DisplayName does not write the name for "Microsoft Visual C++ 2005 Redistributable". how can extract the software name from the $x variable ?

Nabil
  • 41
  • 3
  • 10
  • have you inspected the output for the package? i dont have it installed so i cant do it for you. just run `Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*`, look manually which package is mvc++ 2005 and see if theres a property that contains the name – Paul Nov 26 '14 at 16:54
  • yes inspected it. in fact when i display it using $x , the _Displayname_, the _publisher_ and the _installDate_ are presented on screen. the problem is when i try to access it with _$x.DisplayName_ – Nabil Nov 26 '14 at 16:59
  • hmm thats strange, so $x contains a property Displayname that has a value but $x.Displayname doesnt output it? – Paul Nov 26 '14 at 17:02
  • exactly $x.displayName works fine for the GIMP and other software , but it fails with Microsoft Visual C++ 2005 Redistributable. maybe an issue of length !! – Nabil Nov 26 '14 at 17:10
  • On my system that software is called `Microsoft Visual C++ 2005 Redistributable (x64)` that's why it would not display. See Arco's answer. – Micky Balladelli Nov 26 '14 at 17:13
  • with the WIN32_Product not all software are listed. with the script that i have listed above. the software im looking for are found. juste my problem is to extract the software name from the object. and this hapen only for the Microsoft Visual C++ 2005 Redistributable. when i execute my script with POWERSHELL 64 bit version i will get `Microsoft Visual C++ 2005 Redistributable(x64)` but i will face the same problem : extracting DisplayName from the $x object. – Nabil Nov 26 '14 at 17:25

2 Answers2

0

Can you try this version? It's using your code, with Arco's fixes.

$SoftList = "Microsoft Visual C++ 2005 Redistributable","TotoInexistant","GIMP"

foreach($i in $SoftList)
{
    $x = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    select DisplayName, Publisher, InstallDate | Where-Object {$_.DisplayName -like $("$i*")} 

    $x.DisplayName 

    $x.DisplayName | Out-File "ListOf.txt" -Append -Force
} 

The output I get is:

Microsoft Visual C++ 2005 Redistributable (x64)
GIMP 2.8.14
Micky Balladelli
  • 9,781
  • 2
  • 33
  • 31
  • when i use this version with the 64 bit POWERShell, i get in output: `Microsoft Visual C++ 2005 Redistributable (x64)`. and it looks fine since i don't have a 64 bit versions Installed. However in 32 bit POWERSHELL, it does not display`Microsoft Visual C++ 2005 Redistributable (x64)` – Nabil Nov 27 '14 at 08:43
  • i don't know but when dislaying the $x variable. the "Microsoft Visaul c++ Redistribuable" is present twice.maybe this what prevent to get the name with the command `$x.DisplayName` . – Nabil Nov 27 '14 at 08:54
0

Thanks for your HElp, i found the solution, in fact the $x variable for the Microsoft Visual C++ 2005 Redistributable is an array, maybe because it is installed twice, the
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, Publisher, InstallDate
return two lines containing the informations of Microsoft Visual C++ 2005 Redistributable. to get the displayName in this case i adapt my script as follow :

 if($x-is [array])
 {
   for($k=0;$k-le $x.length-1;$k++)
   {
     $x[$k].DisplayName
   } 
}
Nabil
  • 41
  • 3
  • 10