gpt4 book ai didi

powershell - 查询远程服务器注册表的更好方法?

转载 作者:行者123 更新时间:2023-12-03 01:07:46 25 4
gpt4 key购买 nike

我已经构建了这一小段代码来查询和存储一组服务器的值,这似乎很好用,但是我想知道是否有“纯PowerShell”方式来做到这一点。

$eServers = Get-ExchangeServer
$Servers = $eServers | ?{$_.Name -like "Delimit_server_group"}
foreach ($server in $Servers)
{
[string]$Key1 = "\\$server\HKLM\SYSTEM\CurrentControlSet\Control\"
[string]$rKeys += (REG QUERY "$key1" /s)
}

最佳答案

您可以使用 RegistryKey class打开远程注册表:

$RemoteHKLM = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$server)
$RemoteKey = $RemoteHKLM.OpenSubKey('SYSTEM\CurrentControlSet\Control')
# Following will return all subkey names
$RemoteKey.GetSubKeyNames()

如果您需要等效于 reg query /s的功能,则必须自己实现递归遍历

关于powershell - 查询远程服务器注册表的更好方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45091920/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com