Trouble getting properties and object structured correctly

J.C.

I am trying to create an object with properties identical to the code below. The following bit of code creates the $TempValueICM object with 2 added NoteProperties:

$TempValueICM = Invoke-Command -ComputerName $computer -ScriptBlock {
                $AppPull = Get-ItemProperty HKLM:\software\Microsoft\Windows\CurrentVersion\Uninstall\* |
                    Select-Object DisplayName, DisplayVersion}

It creates $temptValueICM as an array object with NoteProperties of DisplayName and Display version which appear like this:

DisplayVersion : 4.92.12.0

DisplayName : Conexant 20561 SmartAudio HD

DisplayVersion :

DisplayName : Connection Manager

DisplayVersion :

DisplayName : MouseSuite98

...

I am trying to pull the same data using .NET pull with the following code:

$Hive = [Microsoft.Win32.RegistryHive]::LocalMachine
$AppAddressMain = "software\Microsoft\Windows\CurrentVersion\Uninstall\"
$AppAddressWOW = "software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"



Function Get-InstalledApps {
    param ($MainHive, $Computer, [string[]]$RegAddress)

    Foreach($Address in $RegAddress) {
        $RegBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($MainHive, $computer)
        $RegSubKey= $RegBaseKey.OpenSubKey($Address)
        foreach($Subkey in $RegSubKey.GetSubKeyNames()){
            $AppAddress = $Address + $Subkey

            $DisplayName = $($RegBaseKey.OpenSubKey($AppAddress)).GetValue("DisplayName")
            $DisplayVersion = $($RegBaseKey.OpenSubKey($AppAddress)).GetValue("DisplayVersion")
            Write-Output  @{
                DisplayName = $DisplayName
                DisplayVersion = $DisplayVersion
                }
             }
        }

This produces a Hash table data and I can get some information out and access it by using dot notation (e.g. - "$TempValue.DisplayName") but when looking at the object it is showing only "keys" and "values" as object properties for $TempValue object instead of what I would want to be the property names (e.g. - DisplayName and DisplayVersion).

I have tried creating a temporary variable within the function to hold the data as properties e.g. -

 $Temp = "" | select DisplayName, DisplayVersion
     $Temp.DisplayName += ,$DisplayName
     $Temp.Publisher += ,$Publisher
     $Temp.DisplayVersion += ,$DisplayVersion

But that doesn't do it...

Specifically I will eventually have to do a sort-object -properties on it and need for the logic for both functions to be the same (i.e. - so that data can come from either "logic" in the same format so it can be treated the same way.

How do I get the object formatted so the same information is available in the same way as the $TempValueICM above above (i.e. - how do I get the items in the hash table to fill in properties on the object)? Thanks,

user6530384
$Hive = [Microsoft.Win32.RegistryHive]::LocalMachine
$AppAddressMain = "software\Microsoft\Windows\CurrentVersion\Uninstall\"
$AppAddressWOW = "software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"

Function Get-InstalledApps
{
    param ($MainHive,
        $Computer,
        [string[]]$RegAddress)

    Foreach ($Address in $RegAddress)
    {
        $RegBaseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($MainHive, $computer)
        $RegSubKey = $RegBaseKey.OpenSubKey($Address)
        $output = @()
        foreach ($Subkey in $RegSubKey.GetSubKeyNames())
        {
            $AppAddress = $Address + $Subkey
            $DisplayName = $($RegBaseKey.OpenSubKey($AppAddress)).GetValue("DisplayName")
            $DisplayVersion = $($RegBaseKey.OpenSubKey($AppAddress)).GetValue("DisplayVersion")
            $output += [PSCustomObject]@{ DisplayName = $DisplayName; DisplayVersion = $DisplayVersion }
        }
    }
    return $output
}

Get-InstalledApps -MainHive $Hive -Computer "MyPC" -RegAddress $AppAddressMain | sort DisplayName

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Trouble getting arraylist objects returned correctly

From Dev

Trouble getting view to line up correctly

From Dev

Trouble getting input for object array

From Dev

Getting properties object in spring

From Dev

Trouble iterating through properties of an object in JavaScript

From Dev

Having trouble with z-index and getting elements to stack correctly

From Dev

getting python object derived properties

From Dev

Getting object properties that start with a number

From Dev

DesiredCapabilities object not getting its properties

From Dev

JavaScript: Getting evaluated properties of an object

From Dev

Trouble getting a game object from object pool in Unity

From Dev

Trouble instantiating class and adding it to an array - object properties are always 0?

From Dev

Getting Object Properties From External js File

From Dev

Properties disapear after getting the object form the cookiestore

From Dev

getting object properties from a event handler function

From Dev

Having trouble getting access to the Object in JSON from url

From Dev

Trouble getting size of an array in a js object inside controller

From Dev

Having trouble getting access to the Object in JSON from url

From Dev

Trouble correctly handling exceptions

From Dev

Sorting an Structured object

From Dev

Getting Started with Rails Tutorial 5.7: Article object is not being created correctly

From Dev

Form field values are not getting passed into JSON object correctly

From Dev

Trouble with change properties

From Dev

Having trouble with flexbox properties

From Dev

Trouble getting the day of week

From Dev

Trouble getting menu to work

From Dev

Trouble getting fgetc working

From Dev

trouble getting collision point

From Dev

Trouble getting date value

Related Related

  1. 1

    Trouble getting arraylist objects returned correctly

  2. 2

    Trouble getting view to line up correctly

  3. 3

    Trouble getting input for object array

  4. 4

    Getting properties object in spring

  5. 5

    Trouble iterating through properties of an object in JavaScript

  6. 6

    Having trouble with z-index and getting elements to stack correctly

  7. 7

    getting python object derived properties

  8. 8

    Getting object properties that start with a number

  9. 9

    DesiredCapabilities object not getting its properties

  10. 10

    JavaScript: Getting evaluated properties of an object

  11. 11

    Trouble getting a game object from object pool in Unity

  12. 12

    Trouble instantiating class and adding it to an array - object properties are always 0?

  13. 13

    Getting Object Properties From External js File

  14. 14

    Properties disapear after getting the object form the cookiestore

  15. 15

    getting object properties from a event handler function

  16. 16

    Having trouble getting access to the Object in JSON from url

  17. 17

    Trouble getting size of an array in a js object inside controller

  18. 18

    Having trouble getting access to the Object in JSON from url

  19. 19

    Trouble correctly handling exceptions

  20. 20

    Sorting an Structured object

  21. 21

    Getting Started with Rails Tutorial 5.7: Article object is not being created correctly

  22. 22

    Form field values are not getting passed into JSON object correctly

  23. 23

    Trouble with change properties

  24. 24

    Having trouble with flexbox properties

  25. 25

    Trouble getting the day of week

  26. 26

    Trouble getting menu to work

  27. 27

    Trouble getting fgetc working

  28. 28

    trouble getting collision point

  29. 29

    Trouble getting date value

HotTag

Archive