Skip to content

Instantly share code, notes, and snippets.

@pudquick
Created October 31, 2014 00:06
Show Gist options
  • Select an option

  • Save pudquick/b56979bf702cb71ff139 to your computer and use it in GitHub Desktop.

Select an option

Save pudquick/b56979bf702cb71ff139 to your computer and use it in GitHub Desktop.
Powershell check a registry key on IPs
$TESTREG = "SOFTWARE\\Adobe\\Adobe ARM\\1.0\\ARM"
$TESTKEY = "iCheck"
$IPS = Get-Content 'C:\Users\yourname\Desktop\ips.txt'
$OUTPUT = 'C:\Users\yourname\Desktop\ips_log.txt'
function GetName($ipaddr) {
# Resolve a computer name if we can
try {
[System.Net.Dns]::GetHostByAddress($ipaddr).HostName
} catch [System.Exception] {
return $ipaddr
}
}
foreach ($ip in $IPS) {
$compname = GetName $ip
try {
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine",$compname)
$regkey = $reg.opensubkey($TESTREG)
} catch [System.Exception] {
"$ip ($compname)`tERROR (offline or no permission)" | Out-File -FilePath $OUTPUT -Append
Continue
}
try {
$keyvalue = $regkey.GetValue($TESTKEY)
("$ip ($compname)`t{0}" -f $keyvalue) | Out-File -FilePath $OUTPUT -Append
} catch [System.Exception] {
"$ip ($compname)`tNOT FOUND" | Out-File -FilePath $OUTPUT -Append
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment