Created
October 31, 2014 00:06
-
-
Save pudquick/b56979bf702cb71ff139 to your computer and use it in GitHub Desktop.
Powershell check a registry key on IPs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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