尝试在IIS中获取特定名称的应用程序池标识,例如:Test
成功通过下面的代码得到它,但不想遍历所有的webapps,是否有任何容易通过指定名称得到它?
Import-Module WebAdministration
Get-WebApplication
$webapps = Get-WebApplication
$list = @()
foreach ($webapp in get-childitem IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = @{}
if ($webapp.name -eq 'Test')
{
$item = $webapp.processModel.identityType
break
}
}
echo $webapp.processModel.identityType
Run Code Online (Sandbox Code Playgroud)
fia*_*iat 12
不是OP想要的严格意义,但谷歌引导我在这里查询所有App Pool Identities.这是我的版本
Import-Module WebAdministration;Get-ChildItem -Path IIS:\AppPools\ |
Select-Object name, state, managedRuntimeVersion, managedPipelineMode, @{e={$_.processModel.username};l="username"}, <#@{e={$_.processModel.password};l="password"}, #> @{e={$_.processModel.identityType};l="identityType"} |
format-table -AutoSize
Run Code Online (Sandbox Code Playgroud)
只需组合路径并检索项目.这将有效:
$item = Get-Item (Join-Path 'IIS:\AppPools\' 'Test') |
select -ExpandProperty processModel |
select -expand identityType
Run Code Online (Sandbox Code Playgroud)
需要这个,但没有一个答案有完整的代码,所以我把一些东西放在一起。
\n\nTry {\n Import-Module WebAdministration -ErrorAction Stop\n} Catch {\n Write-Error -Message "Unable to load required module."\n}\n\n$webapps = Get-ChildItem \xe2\x80\x93Path IIS:\\AppPools\n$list = [System.Collections.ArrayList]::new()\nforeach ($webapp in $webapps) {\n $Pool = "IIS:\\AppPools\\" + $webapp.name\n $sid = New-Object System.Security.Principal.SecurityIdentifier (\n Get-Item $Pool | select -ExpandProperty applicationPoolSid\n )\n [void]$List.add([PSCustomObject]@{\n Name = $webapp.name\n Pool = $Pool\n ServiceAccount = $sid.Translate([System.Security.Principal.NTAccount])\n })\n}\n$list\n
Run Code Online (Sandbox Code Playgroud)\n\n输出
\n\nName Pool ServiceAccount \n---- ---- -------------- \n.NET v4.5 IIS:\\AppPools\\.NET v4.5 IIS APPPOOL\\.NET v4.5 \n.NET v4.5 Classic IIS:\\AppPools\\.NET v4.5 Classic IIS APPPOOL\\.NET v4.5 Classic\nDefaultAppPool IIS:\\AppPools\\DefaultAppPool IIS APPPOOL\\DefaultAppPool \nWsusPool IIS:\\AppPools\\WsusPool IIS APPPOOL\\WsusPool \n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
16257 次 |
最近记录: |