Get reg key info

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.

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

??? :frowning:

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

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

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

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.

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}

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.

Hi,
still need help

Thanks