Powershell 使用AppCmd仅在APPHOST中列出配置

Powershell 使用AppCmd仅在APPHOST中列出配置,powershell,iis-7,iis-7.5,appcmd,Powershell,Iis 7,Iis 7.5,Appcmd,我需要使用powershell在尚未将代码部署到文件系统的web应用程序上配置IIS7.5(可能根本没有,可能存在旧的/损坏的web.configs)。我希望能够在APPHOST级别完成这一切。(请注意底部有关使用Powershell>AppCmd的说明) 我可以正确地设置所有的值,但是,出于谨慎考虑,我还喜欢通过在设置后检索值来验证这些值设置是否正确 以下是场景: 我可以使用AppCmd设置此值,以便使用/Commit:APPHOST标志在APPHOST级别应用该设置。但是,我还没有找到一种在

我需要使用powershell在尚未将代码部署到文件系统的web应用程序上配置IIS7.5(可能根本没有,可能存在旧的/损坏的web.configs)。我希望能够在APPHOST级别完成这一切。(请注意底部有关使用Powershell>AppCmd的说明)

我可以正确地设置所有的值,但是,出于谨慎考虑,我还喜欢通过在设置后检索值来验证这些值设置是否正确

以下是场景: 我可以使用AppCmd设置此值,以便使用/Commit:APPHOST标志在APPHOST级别应用该设置。但是,我还没有找到一种在APPHOST级别专门读取值的方法

设置代码成功:

C:\Windows\System32\inetsrv\appcmd.exe set config "webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost
但是,我无法找到使用AppCmd(或Powershell)读取值的方法: 运行以下AppCmd返回一个错误,原因是文件夹中预先存在的web.config已损坏(具体错误并不重要,因为它读取的是WebApp的web.config,而不是ApplicationHost.config/APPHOST):


注意:我更喜欢在Powershell中完成这一切,而不是使用AppCmd,因此,如果任何人具有修改web应用程序匿名身份验证部分的APPHOST设置的语法,则可以从Powershell内部(Get WebConfiguration似乎只使用WebApp web.config)修改该web应用程序的匿名身份验证部分,这将是非常棒的,非常感谢

以下是如何在PowerShell中执行此操作:

[Reflection.Assembly]::Load(
"Microsoft.Web.Administration, Version=7.0.0.0, 
Culture=Neutral, PublicKeyToken=31bf3856ad364e35") > $null

$serverManager = New-Object Microsoft.Web.Administration.ServerManager
$config = $serverManager.GetApplicationHostConfiguration()
$anonymousAuthenticationSection = $config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "simpleasp.net")
Write-Host "Current value: " $anonymousAuthenticationSection["enabled"]

# Now set new value
$anonymousAuthenticationSection["enabled"] = $true

$serverManager.CommitChanges()

以下是如何在PowerShell中执行此操作:

[Reflection.Assembly]::Load(
"Microsoft.Web.Administration, Version=7.0.0.0, 
Culture=Neutral, PublicKeyToken=31bf3856ad364e35") > $null

$serverManager = New-Object Microsoft.Web.Administration.ServerManager
$config = $serverManager.GetApplicationHostConfiguration()
$anonymousAuthenticationSection = $config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "simpleasp.net")
Write-Host "Current value: " $anonymousAuthenticationSection["enabled"]

# Now set new value
$anonymousAuthenticationSection["enabled"] = $true

$serverManager.CommitChanges()

如果您在没有服务器管理器的桌面上,您可能需要尝试以下操作:@AUSTX_RJL-为什么不能在桌面上使用服务器管理器?如果您在没有服务器管理器的桌面上,您可能需要尝试以下操作:@AUSTX_RJL-为什么不能在桌面上使用服务器管理器?