Solved

Validate Registry Entry and Return the Values if available using Powershell

Posted on 2014-01-08
5
464 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 300 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
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…

719 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