Подтвердить что ты не робот

Получить значение удаленного реестра

У меня ниже script, что я хочу, чтобы он вышел на несколько серверов и получил значение реестра. К сожалению, в настоящее время просто опубликовано местное значение реестра машины, на котором я запускаю script on.

Как мне заставить script работать с удаленным реестром?

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
    }
}
4b9b3361

Ответ 1

Вы можете попробовать использовать .net:

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

Ответ 2

Попробуйте Удаленный модуль реестра, поставщик реестра не может работать удаленно:

Import-Module PSRemoteRegistry
Get-RegValue -ComputerName $Computer1 -Key SOFTWARE\Veritas\NetBackup\CurrentVersion -Value PackageVersion 

Ответ 3

Если у вас есть удаленная настройка Powershell и настройка CredSSP, вы можете обновить свой код до следующего:

$Session = New-PSSession -ComputerName $Computer1 -Authentication CredSSP
$NetbackupVersion1 = Invoke-Command -Session $Session -ScriptBlock { $(Get-ItemProperty hklm:\SOFTWARE\Veritas\NetBackup\CurrentVersion).PackageVersion}
Remove-PSSession $Session

Ответ 4

Для удаленного реестра вы должны использовать .NET с powershell 2.0

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

Ответ 5

Если вам нужен SID пользователя и просмотреть папку удаленных HKEY_USERS, вы можете следовать этому script:

<# Replace following domain.name with yours and userAccountName with remote username #>
$userLogin = New-Object System.Security.Principal.NTAccount("domain.name","userAccountName")
$userSID = $userLogin.Translate([System.Security.Principal.SecurityIdentifier])

<# We will open HKEY_USERS and with accurate user’s SID from remoteComputer #>
$remoteRegistry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(‘Users’,"remoteComputer")

<# We will then retrieve LocalName value from Control Panel / International subkeys #>

$key = $userSID.value+"\Control Panel\International"
$openKey = $remoteRegistry.OpenSubKey($key)

<# We can now retrieve any values #>

$localName = $openKey.GetValue(‘LocaleName’)

Источник: http://techsultan.com/how-to-browse-remote-registry-in-powershell/

Ответ 6

другой вариант... нужен удаленный доступ...

(invoke-command -ComputerName mymachine -ScriptBlock {Get-ItemProperty HKLM:\SOFTWARE\VanDyke\VShell\License -Name Version }).version

Ответ 7

Использование модуля python и wmi.

import wmi

conn = wmi.WMI('172.20.58.34', user='UserName', password='Password')
command = r'cmd /c reg query "HKLM\SOFTWARE\Microsoft" /ve > C:\output.txt'
conn.Win32_Process.Create(CommandLine=command)

Больше информации $reg/? в командной строке.