我正在尝试让用户完全控制下面脚本中的两个注册表项。该脚本适用于第一个注册表项,但我不知道如何将第二个注册表项添加到同一脚本中。第一个命令完成后,我还需要执行另一个 Invoke - 命令吗?基本上,复制所有内容并将变量更改为 $registrykey2。
$computerName = Read-Host -Prompt "Enter the name of the remote computer"
$username = Read-Host -Prompt "Enter the username"
$registryKey = "HKLM:\SOFTWARE\ODBC"
$registrykey2 = "HKLM:\SOFTWARE\WOW6432Node\ODBC"
$domain = "domain\$username"
$permissionType = "FullControl"
Invoke-Command -ComputerName $computerName -ScriptBlock {
param($registryKey, $domain, $permissionType)
$acl = Get-Acl "$registryKey"
$permission = $domain, $permissionType, "ContainerInherit,ObjectInherit", "None", "Allow"
$accessRule = New-Object System.Security.AccessControl.RegistryAccessRule $permission
$acl.SetAccessRule($accessRule)
Set-Acl "$registryKey" $acl
} -ArgumentList $registryKey, $domain, $permissionType
不幸的是,没有足够的声誉来发表评论,但是,可能是的,您是否尝试过添加第二个 Invoke?有效吗?如果不是,你得到了什么错误? (将根据回复更新答案)