Use AppCmd ​​for LIST CONFIG in APPHOST only

I have a requirement to use powershell to configure IIS7.5 on WebApplications that have not yet deployed the code (perhaps in general, perhaps the old / broken web.configs exist) on the file system. I would like to be able to do all this at the APPHOST level. (Note the use of Powershell> AppCmd ​​below).

I can set all the values ​​correctly, however, being a little diligent, I also like to check the correctness of the values, loading them after setting.

Here's the scenario: I can set this value using AppCmd ​​so that this parameter is applied at the APPHOST level using the / Commit: APPHOST flag. However, I did not find a way to READ the values ​​exclusively at the APPHOST level.

Installing the code successfully:

C:\Windows\System32\inetsrv\appcmd.exe set config "webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost 

However, I cannot find a way to read the values ​​using AppCmd ​​(or Powershell): Running the following AppCmd ​​returns an error due to the previously existing web.config in the folder being broken (the specific error is not important because it reads WebApp web.config instead of ApplicationHost .config / APPHOST):

 C:\Windows\System32\inetsrv\appcmd.exe list config "MACHINE/WEBROOT/APPHOST/webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication ERROR ( message:Configuration error Filename: \\?\c:\inetpub\wwwroot\webSiteName\webAppName\web.config Line Number: 254 Description: The configuration section 'system.runtime.caching' cannot be read because it is missing a section declaration . ) 

Note. I would prefer to do this in Powershell instead of using AppCmd, so if someone has the syntax to change the APPHOST settings for the anonymous WebApplication authentication section that lives under the site, from within Powershell (Get-WebConfiguration seems to use only WebApp web.config) That would be awesome and much appreciated!

+1
source share
1 answer

Here's how to do it in 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() 
+4
source

Source: https://habr.com/ru/post/986515/


All Articles