Detection Script

Welcome Forums General PowerShell Q&A Detection Script

Viewing 4 reply threads
  • Author
    Posts
    • #210819
      Participant
      Topics: 3
      Replies: 5
      Points: 41
      Rank: Member

      I am trying to combine two scripts into 1 so that if I run the 1 script it will detect the products and return a:  installed or not installed.

      Here are my two scripts:

      $software = "Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219";
      
      $installed = (Get-ItemProperty HKLM:\SOFTWARE\Classes\Installer\Products\* | Where { $_.ProductName -eq $software }) -ne $null
      
      If(-Not $installed) {
      
          Write-Host "'$software' NOT is installed.";
      
      } else {
      
          Write-Host "'$software' is installed."
      
      }
      $software = "Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219";
      
      $installed = (Get-ItemProperty HKLM:\SOFTWARE\Classes\Installer\Products\* | Where { $_.ProductName -eq $software }) -ne $null
      
      If(-Not $installed) {
      
          Write-Host "'$software' NOT is installed.";
      
      } else {
      
          Write-Host "'$software' is installed."
      
      }
      I could use some tips to combine both.  I thought about making 2 $ – values?  but I am not sure if that would work.
    • #210822
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      You’re kidding, aren’t you?

      And please format your code as code using the code tags “PRE”. Read Me Before Posting! You’ll be Glad You Did!

      Thanks.

    • #210828
      Participant
      Topics: 3
      Replies: 5
      Points: 41
      Rank: Member

      You’re kidding, aren’t you?

      And please format your code as code using the code tags “PRE”. Read Me Before Posting! You’ll be Glad You Did!

      Thanks.

      I am new to scripting, I am not asking for you to do it for me, just looking for ideas to work with.

    • #210831
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      Ah … ok … so you’re not kidding. Sorry. 😉

      Just run both snippets like they are. if you want to make them one script copy them to one script file and run it. Or did I got something wrong again?

    • #210834
      Participant
      Topics: 12
      Replies: 1622
      Points: 2,560
      Helping Hand
      Rank: Community Hero

      The string is the same with the exception of x86 and x64, so you can do a wildcard search. Both versions of the Runtime are installed, so the question is do you need to know if either is installed or a specific architecture? For instance, this would tell me if either:

      $software = “Microsoft Visual C++ 2019 X* Additional Runtime - 14.22.27821”
      $installed = Get-ItemProperty HKLM:\SOFTWARE\Classes\Installer\Products\* | 
                   Where { $_.ProductName -like $software}
      
      if ($installed) {
          Write-Host (“‘Installed Software: rnrn{0}” -f (($installed | Select -ExpandProperty ProductName) -join "rn"))
      } else {
          Write-Host (“‘{0}’ NOT is installed.” -f $software)
      }
      

      Output:

      Installed Software: 
      
      Microsoft Visual C++ 2019 X86 Additional Runtime - 14.22.27821
      Microsoft Visual C++ 2019 X64 Additional Runtime - 14.22.27821
      

      If you are installing a specific msi for each version, then you can do something like:

      $installed = Get-ItemProperty HKLM:\SOFTWARE\Classes\Installer\Products\*
      
      switch -wildcard ($installed.ProductName) {
          “Microsoft Visual C++ 2019 X86 Additional Runtime - 14.22.27821” {"Do something for x86"}    
          “Microsoft Visual C++ 2019 X64 Additional Runtime - 14.22.27821” {"Do something for x64"}
          default {"Don't care about $_.ProductName"}    
      }
      

      Output:

      Don't care about Office 16 Click-to-Run Extensibility Component.ProductName
      Don't care about Office 16 Click-to-Run Localization Component.ProductName
      Don't care about Office 16 Click-to-Run Extensibility Component 64-bit Registration.ProductName
      Don't care about Office 16 Click-to-Run Licensing Component.ProductName
      Don't care about Microsoft Online Services Sign-in Assistant.ProductName
      Don't care about Microsoft ASP.NET Core 2.2.3 Shared Framework (x64).ProductName
      Don't care about Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.4148.ProductName
      Don't care about Microsoft Visual C++ 2013 x86 Minimum Runtime - 12.0.21005.ProductName
      Don't care about Microsoft Visual C++ 2013 x86 Additional Runtime - 12.0.21005.ProductName
      Don't care about Citrix Workspace Inside.ProductName
      Don't care about Microsoft VC++ redistributables repacked..ProductName
      Don't care about Teams Machine-Wide Installer.ProductName
      Don't care about Zoom Outlook Plugin.ProductName
      Don't care about VMware Horizon Media Redirection for Microsoft Teams.ProductName
      Don't care about Citrix Workspace(Aero).ProductName
      Don't care about VMware Horizon HTML5 Multimedia Redirection Client.ProductName
      Don't care about Citrix Web Helper.ProductName
      Don't care about Intel(R) Trusted Connect Service Client x86.ProductName
      Don't care about Intel(R) Trusted Connect Service Client x64.ProductName
      Don't care about UpdateAssistant.ProductName
      Don't care about Intel(R) Management Engine Components.ProductName
      Don't care about Self-service Plug-in.ProductName
      Don't care about Intel(R) ME UninstallLegacy.ProductName
      Don't care about Microsoft Visual C++ 2013 x64 Additional Runtime - 12.0.21005.ProductName
      Don't care about Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161.ProductName
      Don't care about Citrix Workspace(DV).ProductName
      Don't care about Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.6161.ProductName
      Don't care about Microsoft Visual C++ 2013 x64 Minimum Runtime - 12.0.21005.ProductName
      Don't care about Citrix Screen Casting for Windows.ProductName
      Don't care about VMware Workstation.ProductName
      Don't care about Microsoft .NET Core Host - 2.2.3 (x64).ProductName
      Do something for x86
      Don't care about PowerShell 7-x64.ProductName
      Don't care about Intel(R) Chipset Device Software.ProductName
      Don't care about Microsoft Visual C++ 2019 X86 Minimum Runtime - 14.22.27821.ProductName
      Don't care about Kaspersky Secure Connection.ProductName
      Don't care about Microsoft Exchange Web Services Managed API 2.2.ProductName
      Don't care about VMware Horizon Media Engine 11.0.0.613 (64-bit).ProductName
      Don't care about Google Update Helper.ProductName
      Don't care about Citrix Authentication Manager.ProductName
      Don't care about Microsoft VC++ redistributables repacked..ProductName
      Don't care about Backup and Sync from Google.ProductName
      Don't care about GlobalProtect.ProductName
      Don't care about Microsoft Visual C++ 2019 X64 Minimum Runtime - 14.22.27821.ProductName
      Don't care about Snagit 2020.ProductName
      Don't care about VMware Horizon Client.ProductName
      Don't care about Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148.ProductName
      Don't care about Citrix WorkSpace Browser.ProductName
      Don't care about Intel(R) Management Engine Components.ProductName
      Don't care about Online Plug-in.ProductName
      Don't care about Update for Windows 10 for x64-based Systems (KB4023057).ProductName
      Do something for x64
      Don't care about Remote Desktop Connection Manager.ProductName
      Don't care about Intel® PROSet/Wireless WiFi Software.ProductName
      Don't care about Microsoft .NET Core Host FX Resolver - 2.2.3 (x64).ProductName
      Don't care about Citrix Workspace (HDX Flash Redirection).ProductName
      Don't care about Intel(R) Management Engine Driver.ProductName
      Don't care about Microsoft .NET Core Runtime - 2.2.3 (x64).ProductName
      Don't care about Citrix Workspace(USB).ProductName
      Don't care about Microsoft .NET Core SDK 2.2.105 (x64).ProductName
      
      • This reply was modified 2 months, 2 weeks ago by Rob Simmers.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.