?
Solved

Validate Registry Entry and Return the Values if available using Powershell

Posted on 2014-01-08
5
Medium Priority
?
466 Views
Last Modified: 2014-01-20
I have to Validate Registry Value entry and need if entry is there, need to return the Registry Value Data.
So i have made an external Text file with Registry Path to be Validated.
Following is the Code to verify the Registry entry availability, but it does not work as expected.

Need Assistance in Validating and if Return the Value Data if Registry entry is available.

Code:
-------
function get
{
$RQ = Get-Content C:\Testing\PS\Reg.txt
foreach($RD in $RQ)
{
if(!(Test-Path -Path $rd))
{
Write-Host "RegValue Not Exists!"
}
else
{
Write-Host "RegValue Exists!"
}
}
}
get

Txt File having the registry path to validate:
-------------------------------------------------------
HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon
HKLM:\System\CurrentControlSet\Services\LanmanWorkstation\Parameters\RequireSecuritySignature
HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableCAD
HKLM:\System\CurrentControlSet\Services\LanManServer\Parameters\EnableForcedLogoff
0
Comment
Question by:nssasikumar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 1200 total points
ID: 39764568
Try this..

function get ($file) {
Get-Content $file | % {
$RD = $_
$Name = ($RD -split "\\")[-1]
$Key = $RD -replace "\\$Name$"
	Try{
	$Value = Get-ItemProperty -Path $Key -Name $Name -EA STOP | Select-Object -ExpandProperty $Name
	$Value | Select @{N="Key";E={$RD}},@{N="RegValue";E={$_}}
	}
	Catch{
	"" | Select @{N="Key";E={$RD}},@{N="RegValue";E={"Not Exists!"}}
	}
 }
}
get C:\Testing\PS\Reg.txt | FT -AutoSize

Open in new window


Ref : http://technet.microsoft.com/en-us/library/dd315394.aspx
0
 

Author Comment

by:nssasikumar
ID: 39774334
Works
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39775340
Any particular reason for B grade?

Please see the EE guidelines on grading..
http://support.experts-exchange.com/customer/portal/articles/481419
0
 

Author Comment

by:nssasikumar
ID: 39784444
Just noticed the Grading System, Let me know Is there any possibility of reassign.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question