Answered by:
Query for existence of Registry Key on Remote Machines

Question
-
Need a script that can reach out over the network to Windows XP machines, Windows 2003 machines and Windows 2008 machines to query for the existence of a specific registry key. Does anyone have something they can point me to?Thursday, July 7, 2011 8:57 PM
Answers
-
Enabling winrm is the easiest way. If you have it enabled you can span out to thousands of computers at once with very minimal effort. Otherwise, you can use the .NET interface to opening a remote registry. OR you can use WMI.
$computername = 'T-Alien' # Option #1 using winrm and remoting Invoke-Command -ComputerName $computername -ScriptBlock {Test-Path HKLM:\SOFTWARE} # Option #2 using remote registry $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computername) $regKey= $reg.OpenSubKey("Software") # Option #3 is to use WMI, but I have no code sample for that
| Blog | Twitter | The Windows PowerShell 2.0 Bible |
write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""- Marked as answer by Tiger LiMicrosoft employee Thursday, July 14, 2011 9:23 AM
Friday, July 8, 2011 12:33 AM -
Another example:
$regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Virtual Machine\\Guest\\whatever")
if (!$regKey)
{
Write-host "Not Found"
}
else
{
write-host "Found"
}
http://portal.sivarajan.com/2011/04/identify-physical-host-of-virtual.html
Santhosh Sivarajan | MCTS, MCSE (W2K3/W2K/NT4), MCSA (W2K3/W2K/MSG), CCNA, Network+ Houston, TX
Blogs - http://blogs.sivarajan.com/
Articles - http://www.sivarajan.com/publications.html
Twitter: @santhosh_sivara - http://twitter.com/santhosh_sivara
This posting is provided AS IS with no warranties,and confers no rights.- Marked as answer by Tiger LiMicrosoft employee Thursday, July 14, 2011 9:23 AM
Friday, July 8, 2011 4:35 PM -
- Proposed as answer by SA PRE Monday, July 11, 2011 8:51 AM
- Marked as answer by Tiger LiMicrosoft employee Thursday, July 14, 2011 9:23 AM
Thursday, July 7, 2011 9:00 PM
All replies
-
- Proposed as answer by SA PRE Monday, July 11, 2011 8:51 AM
- Marked as answer by Tiger LiMicrosoft employee Thursday, July 14, 2011 9:23 AM
Thursday, July 7, 2011 9:00 PM -
Enabling winrm is the easiest way. If you have it enabled you can span out to thousands of computers at once with very minimal effort. Otherwise, you can use the .NET interface to opening a remote registry. OR you can use WMI.
$computername = 'T-Alien' # Option #1 using winrm and remoting Invoke-Command -ComputerName $computername -ScriptBlock {Test-Path HKLM:\SOFTWARE} # Option #2 using remote registry $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computername) $regKey= $reg.OpenSubKey("Software") # Option #3 is to use WMI, but I have no code sample for that
| Blog | Twitter | The Windows PowerShell 2.0 Bible |
write-host ((0..56)|%{if (($_+1)%3 -eq 0){[char][int]("116111101110117102102064103109097105108046099111109"[($_-2)..$_] -join "")}}) -separator ""- Marked as answer by Tiger LiMicrosoft employee Thursday, July 14, 2011 9:23 AM
Friday, July 8, 2011 12:33 AM -
Another example:
$regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Virtual Machine\\Guest\\whatever")
if (!$regKey)
{
Write-host "Not Found"
}
else
{
write-host "Found"
}
http://portal.sivarajan.com/2011/04/identify-physical-host-of-virtual.html
Santhosh Sivarajan | MCTS, MCSE (W2K3/W2K/NT4), MCSA (W2K3/W2K/MSG), CCNA, Network+ Houston, TX
Blogs - http://blogs.sivarajan.com/
Articles - http://www.sivarajan.com/publications.html
Twitter: @santhosh_sivara - http://twitter.com/santhosh_sivara
This posting is provided AS IS with no warranties,and confers no rights.- Marked as answer by Tiger LiMicrosoft employee Thursday, July 14, 2011 9:23 AM
Friday, July 8, 2011 4:35 PM