Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get remote registry value

I have the below script that I want it to go out to multiple servers and get the value of a registry. Unfortunately it is currently just posting back the local registry value of the machine that I am running the script on.

How do I get the script to run against remote registry?

SCRIPT:

clear #$ErrorActionPreference = "silentlycontinue"  $Logfile = "C:\temp\NEWnetbackup_version.log"  Function LogWrite {     param([string]$logstring)      Add-Content $Logfile -Value $logstring }  $computer = Get-Content -Path c:\temp\netbackup_servers1.txt  foreach ($computer1 in $computer){  $Service = Get-WmiObject Win32_Service -Filter "Name = 'NetBackup Client Service'" -ComputerName $computer1      if (test-connection $computer1 -quiet)      {             $NetbackupVersion1 = $(Get-ItemProperty hklm:\SOFTWARE\Veritas\NetBackup\CurrentVersion).PackageVersion              if($Service.state -eq 'Running')             {                 LogWrite "$computer1 STARTED $NetbackupVersion1"             }             else             {                 LogWrite "$computer1 STOPPED $NetbackupVersion1"             }     }     else      {         LogWrite "$computer1 is down" -foregroundcolor RED     } } 
like image 770
lara400 Avatar asked Feb 25 '13 14:02

lara400


People also ask

How do I check remote registry?

Go to Start > Run then type "Services. msc". Look for the Remote Registry service. Right-click the Remote Registry service and then select Properties.

How do I find a registry value?

One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive .

How do I get to the registry in PowerShell?

Getting a Single Registry EntryUsing Get-ItemProperty , use the Path parameter to specify the name of the key, and the Name parameter to specify the name of the DevicePath entry. This command returns the standard Windows PowerShell properties as well as the DevicePath property.


2 Answers

You can try using .net:

$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer1) $RegKey= $Reg.OpenSubKey("SOFTWARE\\Veritas\\NetBackup\\CurrentVersion") $NetbackupVersion1 = $RegKey.GetValue("PackageVersion") 
like image 140
CB. Avatar answered Sep 23 '22 17:09

CB.


Try the Remote Registry Module, the registry provider cannot operate remotely:

Import-Module PSRemoteRegistry Get-RegValue -ComputerName $Computer1 -Key SOFTWARE\Veritas\NetBackup\CurrentVersion -Value PackageVersion  
like image 36
Shay Levy Avatar answered Sep 21 '22 17:09

Shay Levy