powershell - 使用 Powershell 命令将计算机添加到事件日志读取器组

标签 powershell scripting usergroups

我需要将计算机添加到事件日志读取器组。我尝试过下面的脚本。

$hostName = "Hostname"
$computername = $env:computername
$EventLogGroup = [adsi]"WinNT://$computername/Event Log Readers,group"
$temp = "WinNT://$hostName"
$EventLogGroup.Add($temp)

相同的脚本可用于将用户添加到组中以及添加未添加的计算机。

我认为我们需要将对象类型更改为计算机。位置将位于同一域中。

任何修改或替代脚本都会有帮助

“无法将成员添加到本地组或从本地组中删除成员,因为该成员不存在”这是我在执行脚本时遇到的错误

最佳答案

尝试在计算机名称后面添加域名和美元符号:

$temp = "WinNT://DomainName/$hostName$,computer"

关于powershell - 使用 Powershell 命令将计算机添加到事件日志读取器组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12154389/

相关文章:

powershell - 如何删除文件名中括号内的所有字符串?

powershell - powershell 将文件移动到 Amazon s3

.net - 通过反射加载程序集成功,Add-Type 不成功

linux - shell脚本的单元测试

powershell - Powershell:使用变量在脚本 block 中引用$ _的属性

c# - 使用 EnvDTE.ExecuteCommand 以编程方式开始调试特定项目

linux - Bash/Sh 等 Shell 脚本的 IDE/Emacs 模式

linux - 无法将用户添加到 docker 组

puppet - 使用 Puppet 将用户添加到多个组

php - 允许用户从自定义 Joomla 登录表单中选择用户组