Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

powershell - 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:empNEWnetbackup_version.log"

Function LogWrite
{
    param([string]$logstring)

    Add-Content $Logfile -Value $logstring
}

$computer = Get-Content -Path c:emp
etbackup_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:SOFTWAREVeritasNetBackupCurrentVersion).PackageVersion

            if($Service.state -eq 'Running')
            {
                LogWrite "$computer1 STARTED $NetbackupVersion1"
            }
            else
            {
                LogWrite "$computer1 STOPPED $NetbackupVersion1"
            }
    }
    else 
    {
        LogWrite "$computer1 is down" -foregroundcolor RED
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can try using .net:

$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer1)
$RegKey= $Reg.OpenSubKey("SOFTWARE\Veritas\NetBackup\CurrentVersion")
$NetbackupVersion1 = $RegKey.GetValue("PackageVersion")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...