Reputation: 91
Im trying to create a Powershell script that can show me a list of all the Registry Keys from "Test" (Screenshot1).
Every Key has a StringValue "Version". I need to know the value from each.
The output should be something like this:
Sub1 Version: 112
Sub2 Version: 112
Bus3 Version: 111
I also would need to know the value of "Server" from Setting of each Key. (Screenshot2)
It should look something like this in the end:
Sub1 Version: 112 Server: 2012
Sub2 Version: 112 Server: 2008
Bus3 Version: 111 Server: 2012
I've tried to get it working by using "get-childitem" and "get-itemproperty", but failed in the end due to lack of experience. I don't understand how to get it to work to show me the desired output. Does anyone have an idea on how this can be done?
Upvotes: 0
Views: 987
Reputation: 91
Here is my solution
$file = "c:\temp\RegistryValues.txt"
$items = Get-Item "HKLM:\SOFTWARE\WOW6432Node\Test\*"
$items2 = $items | select -ExpandProperty name
$items2 | % {
$i = $(($_).split("\")[-1])
$j = $(Get-ItemPropertyValue "Registry::$_" -Name 'version')
$k = $(Get-ItemPropertyValue "Registry::$_\Setting" -Name 'Server')
"$i Version: $j Setting: $k" | add-content $file
}
Upvotes: 0
Reputation: 8346
Here's a sample script that doesn't exactly answer your question. But it shows how to access the registry keys and values.
function ShowDotNetVersion
{
# http://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
$p = Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" -Name Release -ErrorAction SilentlyContinue
if ($p -eq $null) { $rc = "UNKN" }
else { $rc = $p.Release.ToString() }
if ($rc -eq "378389") { $rc = ".NET 4.5" }
if ($rc -eq "378675") { $rc = ".NET 4.5.1/Windows 8.1" }
if ($rc -eq "378758") { $rc = ".NET 4.5.1" }
if ($rc -eq "381023") { $rc = ".NET 4.5.1/Windows 10/9860" }
if ($rc -eq "381029") { $rc = ".NET 4.5.1/Windows 10/9896" }
if ($rc -eq "394254") { $rc = ".NET 4.6/Windows 10" }
Write-Host ".NET framework $rc is installed"
$p = (Get-ItemProperty "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" -Name Version -ErrorAction SilentlyContinue).Version.ToString()
Write-Host ".Net framework version is $($p)"
}
This is part of my powershell startup script so I run it multiple times per day. Maybe it can inspire you to self-answer your own question.
Upvotes: 1