确保将 IIS AppPool 用户添加到 windows 组

Ensure that IIS AppPool user is added to windows group

我正在尝试使用 Powershell(运行 by Ansible)将 ASP.NET 应用程序部署到 IIS。

我希望我的应用程序能够查询性能计数器,因此我使用此 Powershell 脚本将其添加到性能监视器用户中:

appPoolName=$args[0]

$group = [ADSI]"WinNT://$Env:ComputerName/Performance Monitor Users,group"

$ntAccount = New-Object System.Security.Principal.NTAccount("IIS AppPool$appPoolName")
$strSID = $ntAccount.Translate([System.Security.Principal.SecurityIdentifier])
$user = [ADSI]"WinNT://$strSID"

$group.Add($user.Path)

它实际上来自另一个SO问题:Add IIS AppPool\ASP.NET v4.0 to local windows group

部署后,可能会出现将用户添加到组但应用程序仍然无法访问性能计数器的情况。

脚本 运行 就在启动应用程序池和应用程序之前。 我尝试了以下方法,但没有成功:

我通过以下方式修改了我的部署脚本,但没有成功:

解决我的问题的唯一方法是重启机器。我想知道有没有更好的!

如果可能的话,我认为让 App Pool 用户注销并重新登录可以解决我的问题。我还没有找到如何做到这一点(重新启动或回收应用程序池不起作用)。

答案很简单 iisreset(在命令行或 Powershell 中)。