question

DHoss-6479 avatar image
0 Votes"
DHoss-6479 asked JonathanLyons-9754 edited

How to get multiple value data from remote registry key

I am trying to get two value data in one line. It works fine when I do it in two line but I want to use one line code. Any help would be appreciated.
Here is my code:

Blockquote

$Getservice = Get-Service -ComputerName $Computer -Name RemoteRegistry
If ($Getservice.Status -eq "Stopped") {
Set-service -ComputerName $Computer -Name RemoteRegistry -Status Running -StartupType Manual -ErrorAction stop


$regcon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $Computer)
$regkey = $regcon.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\")
$gvalue = $regkey.GetValue('DisplayVersion')
$winver = $regkey.GetValue('ReleaseID')
}
Do {
Get-service -ComputerName $Computer -Name RemoteRegistry | Stop-Service -Force
Set-Service -ComputerName $Computer -Name RemoteRegistry -Status Stopped -StartupType Disabled
$StopRemoteRegistry = Get-Service -ComputerName $Computer -Name RemoteRegistry
} while($StopRemoteRegistry.StartType -eq "Enabled")

Blockquote

I am trying to accomplish...
$winver = $regkey.GetValue('ReleaseID', 'DisplayVersion')



windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered DHoss-6479 commented

Do you want a single STRING or do you want an ARRAY?

 # as a string
 $winver = "{0} {1}" -f $regkey.GetValue('DisplayVersion'), $regkey.GetValue('ReleaseID')
    
 # as an array
 $winver = $regkey.GetValue('DisplayVersion'), $regkey.GetValue('ReleaseID')

I'm curious: Why does it have to be done in one line of code?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The reason I need it as I have another script where I use a list view form, and I want to use the data in one row. I tried already wht u did but it does not work. And I think as it is list view it has to do something . The code I use as as follows: add.SubItem does not take two variable. And that is I am looking to do. I am not sure whether it is possible or not. I appreciate u r answer.

 if($XML.Options.SystemInfo.OS.WindowsVersion.Enabled -eq $true){

$Item = New-Object System.Windows.Forms.ListViewItem("Display Version")
$Item.SubItems.Add($winver)
$lvMain.Items.Add($Item)
}
if($XML.Options.SystemInfo.OS.ServicePack.Enabled -eq $true){
$Item = New-Object System.Windows.Forms.ListViewItem("Release ID")
$Item.SubItems.Add($regvalue)
$lvMain.Items.Add($Item)
}

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered DHoss-6479 commented

This (using only a local machine) produces a single string in the $winver variable:

 $regcon = [Microsoft.Win32.RegistryKey]::OpenBaseKey("LocalMachine","Registry64")
 $regkey = $regcon.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion\")
 # as a string
 $winver = "{0} {1}" -f $regkey.GetValue('ReleaseID'),$regkey.GetValue('DisplayVersion')
    
 $winver

Since you provide no explanation of how "it does not work" I have no idea how to help you,

· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I mentioned that add.SubItem only represent one value of $winver or $regvalue. I can get them in two seperate list view but I want to get two value data in one add.SubItem. Hope u got it now

0 Votes 0 ·

The code produces a value that looks like this: 21H1 2009

That's a single string. One item.

I hope YOU get it now!

1 Vote 1 ·
DHoss-6479 avatar image DHoss-6479 RichMatheisen-8856 ·

Hi, thank u so much. Yes it works. I really appreciate it.

0 Votes 0 ·
Show more comments