如何使用PowerShell修改IIS配置编辑器中的指定Windows认证配置项?
PowerShell 修改IIS Windows认证useAppPoolCredentials配置实现方法
前置准备
- 必须以管理员权限启动PowerShell,否则无修改IIS配置文件的权限
- 若未安装IIS管理PowerShell模块,可执行以下命令启用对应功能:
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementScriptingTools -NoRestart
推荐实现方法(原生PowerShell)
修改结果和直接在IIS配置编辑器中手动操作完全一致,可直接复制执行:
- 导入WebAdministration模块
Import-Module WebAdministration - 为默认站点修改指定配置
Set-WebConfigurationProperty -Filter "system.webServer/security/authentication/windowsAuthentication" -Name "useAppPoolCredentials" -Value $true -PSPath "IIS:\Sites\Default Web Site"
若需为所有IIS站点统一配置该参数,去掉上述命令中的
-PSPath "IIS:\Sites\Default Web Site"参数即可。
备选实现方法(AppCmd命令调用)
IIS原生自带的AppCmd工具可通过PowerShell直接调用完成配置:
C:\Windows\System32\inetsrv\appcmd.exe set config "Default Web Site" /section:windowsAuthentication /useAppPoolCredentials:true /commit:apphost
- 若需配置全局参数,将命令中的
"Default Web Site"替换为空字符串即可 /commit:apphost参数指定将配置写入IIS全局配置文件,避免改动站点目录下的web.config
配置验证
执行以下命令,返回值为True即代表配置生效:Get-WebConfiguration -Filter "system.webServer/security/authentication/windowsAuthentication" -PSPath "IIS:\Sites\Default Web Site" | Select-Object -ExpandProperty useAppPoolCredentials
常见注意事项
- 若站点名称不是默认的
Default Web Site,可通过Get-Website命令查询当前所有站点的准确名称,替换命令中对应的路径参数 - 若修改后配置未生效,可执行
iisreset重启IIS服务后重新验证 - 所有修改默认会写入
C:\Windows\System32\inetsrv\config\applicationHost.config文件,与IIS配置编辑器中展示的配置完全对应
内容的提问来源于stack exchange,提问作者עומר אנגי
相关产品推荐
相关产品推荐

