Get reg key info

Welcome Forums General PowerShell Q&A Get reg key info

This topic contains 9 replies, has 3 voices, and was last updated by

 
Participant
2 years ago.

  • Author
    Posts
  • #54736

    Participant
    Points: 0
    Rank: Member

    Hi,

    i try to get reg key information from remote comp:

    $InstFile = {
    $AllKeys = @()
    $key_Wow6432 = Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Test"
    Foreach ($key in $key_Wow6432)
    {
    $Object1 = New-Object PSObject
    Add-Member -inputObject $Object1 -memberType NoteProperty -name "StubPath" -value $key.StubPath
    Add-Member -inputObject $Object1 -memberType NoteProperty -name "Version" -value $key.Version
    $AllKeys += $Object1
    }
    #Additional registry check
    If ($key_32 = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Test2" -ErrorAction SilentlyContinue)
    {
    Foreach ($key2 in $key_32)
    {
    $Object2 = New-Object PSObject
    Add-Member -inputObject $Object2 -memberType NoteProperty -name "StubPath" -value $key2.StubPath
    Add-Member -inputObject $Object2 -memberType NoteProperty -name "Version" -value $key2.Version
    $AllShareFileKeys += $Object2
    }
    #Additional registry check
    If ($key_33 = Get-ItemProperty "HKCU:\Software\Citrix\ShareFile\SSO" -ErrorAction SilentlyContinue)
    {
    Foreach ($key3 in $key_33)
    {
    $Object3 = New-Object PSObject
    Add-Member -inputObject $Object3 -memberType NoteProperty -name "Method" -value $key3.Method
    Add-Member -inputObject $Object3 -memberType NoteProperty -name "Subdomain" -value $key3.Subdomain

    $AllShareFileKeys += $Object3

    }
    }
    }
    $AllKeys
    }
    #Establish remote connection
    $InstSoftObj = Invoke-Command -ComputerName "TEST12" -ScriptBlock $InstFile | Export-Csv "C:\Reg.csv" -NoTypeInformation

    in output i see just one line, but i want to see 6 lines per machine

    Thanks.

  • #54744

    Participant
    Points: 21
    Rank: Member

    1..100 | %{[string]$_ + '. six lines /machine'}

  • #54752

    Participant
    Points: 0
    Rank: Member

    ??? 🙁

  • #54764

    Participant
    Points: 10
    Rank: Member

    Try something like this for your scriptblock.

    # Scriptblock
    $command = {
    $regpaths = @"
    HKLM:\SOFTWARE\Wow6432Node\Microsoft\Test
    HKLM:\SOFTWARE\Microsoft\Test2
    HKCU:\Software\Citrix\ShareFile\SSO
    "@ -split "`n"
    $regpaths = $regpaths.Trim()
    
    # Get Registry key info
    $regkeys = foreach ($path in $regpaths){
    $reg = Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue | Get-ItemProperty
    $reg | ForEach-Object {[PSCustomObject]@{
            StubPath = $_.StubPath
            Version = $_.Version
            Method = $_.Method
            Subdomain = $_.Subdomain}
    }}  
    $regkeys | Export-Csv C:\regkeys.csv -NoTypeInformation
    }
    
    # Connect
    Invoke-Command -ComputerName "TEST12" -ScriptBlock $command
    
  • #54768

    Participant
    Points: 0
    Rank: Member

    Thank you for example, but i get error:
    Method invocation failed because [System.String[]] doesn't contain a method named 'Trim'.

  • #54771

    Participant
    Points: 10
    Rank: Member

    I was using PowerShell v.3 for my previous post. Your remote systems may be running PowerShell v.2. Try this.

    # Scriptblock
    $command = {
    $regpaths = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Test
    HKLM:\SOFTWARE\Microsoft\Test2
    HKCU:\Software\Citrix\ShareFile\SSO" 
    $regpaths = ($regpaths.Trim() -split "`n")
    
    # Get Registry key info
    $array = New-Object -TypeName System.Collections.ArrayList
    foreach ($path in $regpaths){
    Get-ChildItem -Path $path -Recurse -ErrorAction SilentlyContinue | 
    Get-ItemProperty | ForEach-Object {
    $regobj = New-Object -TypeName PSObject
    Add-Member -InputObject $regobj -MemberType NoteProperty -Name 'StubPath' -Value $_.StubPath
    Add-Member -InputObject $regobj -MemberType NoteProperty -Name 'Version' -Value $_.Version
    Add-Member -InputObject $regobj -MemberType NoteProperty -Name 'Method' -Value $_.Method
    Add-Member -InputObject $regobj -MemberType NoteProperty -Name 'Subdomain' -Value $_.Subdomain
    $array.add($regobj) | Out-Null
    }} 
    $array | Export-Csv C:\regkeys.csv -NoTypeInformation
    }
    
    # Connect
    Invoke-Command -ComputerName "TEST12" -ScriptBlock $command
    
  • #54817

    Participant
    Points: 0
    Rank: Member

    Hi random commandline,

    Thank you for help
    now script working with no error, but scv file empty

    also how if i need run this script on multiple machines, can it create scv file on my machine not on user

    Thanks.

  • #54822

    Participant
    Points: 10
    Rank: Member

    Verify if the property names, stubpath, version, method, and subdomain, exist and have values in your registry.
    For example, this should display property names and values.

      Get-ChildItem HKLM:\HARDWARE\DESCRIPTION | Get-ItemProperty 

    To export all results for each machine to your local, change the export part to this and run Invoke cmdlet in a loop for multiple machines.

    Export-Csv “C:\$($machine)_regkeys.csv” -NoTypeInformation
    Foreach ($machine in $listofmachines){Invoke-Command -ComputerName “$machine" -ScriptBlock $command}
    
  • #54850

    Participant
    Points: 0
    Rank: Member

    Hi,
    i checked and 2 keys have stubpath and version, and one key have method and subdomain but no stubpath and version

    and it's still create blank csv on user computer

    Thanks.

  • #55002

    Participant
    Points: 0
    Rank: Member

    Hi,
    still need help

    Thanks

The topic ‘Get reg key info’ is closed to new replies.