Check Registry For Key Value – Windows PowerShell Script

Posted By on Apr 11, 2012 | 0 comments


I wrote this script so you can loop through a CSV which contains a list of IP’s or Hostnames and allows you to verify whether a specific Registry Key and Value exist. Of course this can be modified for further granularity.

[message_box type=”info” icon=”yes”]
# Filename: checkreg.ps1
# Description: Imports a list of computers from a CSV file and then checks each of the
# computersa particular registry key. If the key is not present script will notify with the
# IP or Hostname of that computer.
# Created By: Matthew Costello
# Date: 04-11-2012

import-module PSRemoteRegistry

$computerNames = Import-Csv ‘c:computers.txt’ #import in csv of computers with a header of server
$file = “C:patchresults.txt”

foreach ($entry in $computerNames) #loop through each entry
{

$server = $entry.server

#pass in server, do a ping to see if it is alive, else error, set Hive of Local Machine, Key of key path and value I am looking for. Will return true or false

$regvalue1 = Test-RegValue -ComputerName $server -ping -Hive LocalMachine -Key ‘SOFTWAREPoliciesMicrosoftWindowsWindowsUpdate’ -Value ‘WUServer’

$regvalue2 = Test-RegValue -ComputerName $server -ping -Hive LocalMachine -Key ‘SOFTWAREPoliciesMicrosoftWindowsWindowsUpdate’ -Value ‘WUStatusServer’

if($regvalue1 -eq $false)
{
Write-Output $entry ” WUServer ” | Out-File $file -append;
}

if($regvalue2 -eq $false)
{
Write-Output $entry ” WUStatusServer ” | Out-File $file -append;
}

}

[/message_box]