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 } }
Go to Start > Run then type "Services. msc". Look for the Remote Registry service. Right-click the Remote Registry service and then select Properties.
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 .
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.
You can try using .net:
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer1) $RegKey= $Reg.OpenSubKey("SOFTWARE\\Veritas\\NetBackup\\CurrentVersion") $NetbackupVersion1 = $RegKey.GetValue("PackageVersion")
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With