locked
Problem: Adding-Members to an Object RRS feed

  • Question

  • Hi all. I'm trying to program a script that captures all the software installed on a users PC and check to see if the softwares match with what I have populated in a CSV list that I have made. The end goal is to add a coliumn "Match" which states either "Y" or "N".

    I'm grabbing the list of installed software by making a query into the registry:

    $appsOnPC = 
    @( 
        if (Test-Path “HKLM:$uninstallWow6432Path”) { Get-ChildItem “HKLM:$unistallWow6432Path” } 
        if (Test-Path “HKLM:$uninstallPath” ) { Get-ChildItem “HKLM:$unistallPath” } 
    ) | ForEach-Object { Get-ItemProperty $_.PSPath } | Where-Object { $_.DisplayName -and !$_.SystemComponent -and !$_.ReleaseType -and !$_.ParentKeyName -and $_.UninstallString -and !$_.NoRemove } | Select-Object DisplayName, @{n='Version'; e={$_.DisplayVersion}}, @{n='InstallDate'; e={([datetime]::parseexact(($PSItem.InstallDate), 'yyyyMMdd', $null)).ToShortDateString()}} | Sort-Object DisplayName

    This gives me a list of installed software on the system with their:

    DisplayName  |  Version  |  InstallDate

    But like I said I only want to check against the list in the CSV. The CSV looks like this:

    AppName  |  Version

    $sourceData = Import-CSV C:\Users\kjanjuha\Desktop\Apps.csv

    The similarities between the objects are DisplayName and AppName (which are the names of all the apps) and Version (version of the apps).

    I've managed to find the apps which are/aren't similiar by using a ForLoop:

    foreach ($app in $appsOnPC) {
    if($sourceData.AppName -contains $app.DisplayName) 
    {'Y'}
    else 
    {'N'}
    } 

    But I want to append this list into a property called "Match" in the $appsOnPC object so it looks like this

    DisplayName  |  Version  |  InstallDate   |  Match
    MSOffice        | 16.0...    |  14/06/2017  |    Y
    GoogleDrive   | 2.0...      |  14/06/2017  |    N

    I've looked online and I seem to get a lot around Add-Member. Any thoughts?

    I really appreciate all the help!


    • Edited by K.Janjuha Wednesday, June 14, 2017 12:46 PM
    Wednesday, June 14, 2017 12:44 PM

Answers

All replies

  • There's no need to reinvent the wheel. Use this script:

    Windows IT Pro - Auditing 32-Bit and 64-Bit Applications with PowerShell


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 14, 2017 1:24 PM
  • using your example, I would do something like this

    foreach ($app in $appsOnPC) {

    if($sourceData.AppName -contains $app.DisplayName) {

    $props = @{'DisplayName' = $app.DisplayName; 'Version' = $app.DisplayName; 'InstallDate' = $app.InstallDate; 'Match' = "Y"}

    $data|new-object psobject -properties $props

    } $props = @{'DisplayName' = $app.DisplayName; 'Version' = $app.DisplayName; 'InstallDate' = $app.InstallDate; 'Match' = "N"}

    $data|new-object psobject -properties $props}

    $data|export-csv .\apps.csv

    Thursday, June 15, 2017 6:47 AM