Script to check if a reg key is set on multiple servers


Summary

If your servers require a reg key and unsure if its properly configured. You can use this script to check if the key is present or is set to the correct value across multiple servers.

The Script

#Simple Server list
$servers = Get-Content C:\servers.txt
 
# Loop through all servers and check key 
foreach ($server in $servers) {
 
$REG = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)
$REGKEY = $REG.OpenSubKey("SYSTEM\CurrentControlSet\Control\Lsa")
$val = $REGKEY.GetValue("DisableLoopBackCheck")
 
# If the key is missing or not set it will be displayed in red
# If the key is set it will be displayed in green
 
if (!$val){
 
Write-Host $server "is not set"  -ForegroundColor Red
break
}
 
if ($val -ne "1"){
Write-Host $server "is not set properly"  -ForegroundColor Red
}
 
else{
Write-Host $server "is set" -ForegroundColor Green
}
}

What the Script Does

In the sample above it will check the “DisableLoopBackCheck” key across a list of servers and if the key does not exist or not set to “1” it will be reported in the output.

 

Example:

 
You can simply change which key to check and the desired value to make this work for your scenario.

 
I hope this helps make your job easier in the future.

Skip to main content