修改同一域内另一台PC上的注册表

时间:2018-03-20 15:26:33

标签: powershell

我是PowerShell菜鸟,所以请放轻松。这是我到目前为止所得到的。脚本的其余部分应该没问题。我在连接到域上的另一台PC时遇到了麻烦。

我也启动了RemoteRegistry流程,因此这不应该是一个问题(连同等待命令)。

我确实需要找到一种与同一域上的另一台PC进行交互的方法。我已经尝试过的cmdts还没有多大用处。我可能只是错误地使用它们。我基本上只需要向远程PC添加一个注册表项,而不是登录到他们的机器并手动完成。

这是我迄今为止所尝试过的:

$computer ="xxxxxx"
Get-WmiObject Win32_BIOS -ComputerName $computer

我也尝试过:

$computer ="xxxxx"
Get-ADComputer -Identity $computer

1 个答案:

答案 0 :(得分:2)

这是一个与远程注册表交互的wmi方法:

$PSCredential = Get-Credential
$ComputerName = Read-Host -Prompt 'Enter target computername'

$GwmiArgs = @{
    Class        = 'StdRegProv'
    Namespace    = 'Root\Default'
    List         = $True
    ComputerName = $ComputerName
    Credential   = $PSCredential
}
$Registry = Get-WmiObject @GwmiArgs

使用此$Registry对象,您有以下方法:
(它们都返回[System.Management.ManagementBaseObject]个对象)

CheckAccess            ([uint32] $DefKey, [string] $SubKeyName, [uint32] $Required)
CreateKey              ([uint32] $DefKey, [string] $SubKeyName)
DeleteKey              ([uint32] $DefKey, [string] $SubKeyName)
DeleteValue            ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName)
EnumKey                ([uint32] $DefKey, [string] $SubKeyName)
EnumValues             ([uint32] $DefKey, [string] $SubKeyName)
GetBinaryValue         ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName)
GetDWORDValue          ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName)
GetExpandedStringValue ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName)
GetMultiStringValue    ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName)
GetQWORDValue          ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName)
GetSecurityDescriptor  ([uint32] $DefKey, [string] $SubKeyName)
GetStringValue         ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName)
SetBinaryValue         ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName, [byte[]] $Value)
SetDWORDValue          ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName, [uint32] $Value)
SetExpandedStringValue ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName, [string] $Value)
SetMultiStringValue    ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName, [string[]] $Value)
SetQWORDValue          ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName, [uint64] $Value)
SetSecurityDescriptor  ([uint32] $DefKey, [string] $SubKeyName, [System.Management.ManagementObject#__SecurityDescriptor] $Descriptor)
SetStringValue         ([uint32] $DefKey, [string] $SubKeyName, [string] $PropertyName, [string] $Value)

并添加远程注册表项:

<#  Defined in WinReg.h:
        HKEY_CLASSES_ROOT (2147483648)
        HKEY_CURRENT_USER (2147483649)
        HKEY_LOCAL_MACHINE (2147483650)
        HKEY_USERS (2147483651)
        HKEY_CURRENT_CONFIG (2147483653)
#>
$HKEY_LOCAL_MACHINE = 2147483650
$Registry.CreateKey($HKEY_LOCAL_MACHINE, 'SYSTEM\path\to\offlinecachekey')