我正在尝试使用 PowerShell 编写脚本,将用户 IIS AppPool\ASP.NET v4.0 添加到 Performance Monitor Users 组,以便能够从 ASP.NET 应用程序使用自定义性能计数器。但是,我不知道如何使用 ADSI 处理自动创建的 ASP.NET 用户。
这对我有用:
$computer = $env:COMPUTERNAME;
$user = [ADSI]"WinNT://$computer/Administrator,user"
$groupToAddTo = "TestGroup"
$parent = [ADSI]"WinNT://$computer/$groupToAddTo,group"
$parent.Add($user.Path)
但是,我不知道如何找到 ASP.NET v4.0 用户:
$computer = $env:COMPUTERNAME;
# $user = [ADSI]"WinNT://$computer/IIS AppPool/ASP.NET v4.0,user" # <-- Doesn't work
$groupToAddTo = "TestGroup"
$parent = [ADSI]"WinNT://$computer/$groupToAddTo,group"
$parent.Add($user.Path)
关于如何使用 ADSI 解决该用户的任何线索?或者,使用 Powershell 或其他命令行工具实现我想要的任何其他绝妙方法? GUI 工作正常,但是,自动化是这里的关键。
最佳答案
以下 PowerShell 脚本会将应用程序池“ASP.NET v4.0”添加到“Performance Monitor Users”组
$group = [ADSI]"WinNT://$Env:ComputerName/Performance Monitor Users,group"
$ntAccount = New-Object System.Security.Principal.NTAccount("IIS APPPOOL\ASP.NET v4.0")
$strSID = $ntAccount.Translate([System.Security.Principal.SecurityIdentifier])
$user = [ADSI]"WinNT://$strSID"
$group.Add($user.Path)
与 net localgroup
命令不同,此脚本适用于长度超过 20 个字符的应用程序池名称。
关于windows - 将 IIS AppPool\ASP.NET v4.0 添加到本地窗口组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18208890/