将IIS AppPool\ASP.NET v4.0添加到本地Windows组 [英] Add IIS AppPool\ASP.NET v4.0 to local windows group

查看:147
本文介绍了将IIS AppPool\ASP.NET v4.0添加到本地Windows组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PowerShell编写脚本,将用户 IIS AppPool\ASP.NET v4.0 添加到 Performance Monitor Users 组中,能够使用来自ASP.NET应用程序的自定义性能计数器。但是,我不知道如何使用ADSI处理自动创建的ASP.NET用户。

I'm trying to script with PowerShell the act of adding the user IIS AppPool\ASP.NET v4.0 to the Performance Monitor Users group, to be able to use custom performance counters from an ASP.NET application. But, I can't figure out how to address the automatically created ASP.NET user using ADSI.

这对我有用:

 $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用户:

However, I can't figure out how to find the ASP.NET v4.0 user:

 $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工作正常,但是,自动化是这里的关键。

Any clues on how to address that user using ADSI? Or, any other brilliant ways to achieve what I want using Powershell or other command-line tools? GUI works fine, however, automation is the key here.

推荐答案

以下PowerShell脚本将添加应用程序池 ASP.NET v4.0添加到性能监视器用户组

The following PowerShell script will add the application pool "ASP.NET v4.0" to the group "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个字符。

Unlike the net localgroup command, this script will work fine with app pool names longer than 20 characters.

这篇关于将IIS AppPool\ASP.NET v4.0添加到本地Windows组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆