2012-01-25 2 views
1

powershell을 사용하여 파일 시스템에 아직 코드가 배포되지 않은 WebApplications에 IIS7.5를 구성해야한다는 요구 사항이 있습니다 (가능하면 오래되었거나 손상된 web.configs가있을 수 있음). . 나는 APPHOST 레벨에서이 모든 것을 할 수 있기를 바란다. (Powershell> AppCmd ​​사용에 대해서는 하단에 있습니다.)AppCmd를 사용하여 APPHOST에서만 구성 가능

필자는 모든 값을 올바르게 설정할 수 있지만 다소 성실한 것으로 설정 한 후 값을 올바르게 설정했는지 확인하고 싶습니다.

여기에 시나리오가 있습니다. /Commit : APPHOST 플래그를 사용하여 APPHOST 수준에서 설정이 적용되도록 AppCmd를 사용하여이 값을 설정할 수 있습니다. 그러나 APPHOST 수준에서만 독점적으로 값을 읽는 방법을 찾지 못했습니다.

코드를 설정하면 성공 그러나

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

, 내가 APPCMD 명령어 (또는 파워 쉘)를 사용하여 값을 읽을 수있는 방법을 찾을 수 없습니다 : 인해 다음 APPCMD 명령어를 실행하면 오류를 반환 을 깨진 기존 폴더에 web.config 반면 (그 대신이 ApplicationHost.config/APPHOST의 웹 애플리케이션의 web.config을 읽고으로 특정 오류는 중요하지 않습니다) :

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 
.) 

참고 : 나는 모든 PowerShell에서이 작업을 수행하는 것을 선호 AppCmd를 사용하는 대신 누군가 Powershell 내부에서 웹 사이트 (Get-WebConfiguration은 WebApp web.config 만 사용하는 것처럼 보임)의 웹 애플리케이션 아래에있는 WebApplication의 anonymousAuthentication 섹션에 대한 APPHOST 설정을 수정하는 구문이있는 경우 이는 대단히 감사 할 것입니다.

답변

4

여기 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() 
+0

당신이 ServerManager 클래스없이 바탕 화면에 경우이 같은 것을 시도해야 할 수 있습니다 https://github.com/jefflomax/configure-iis -webapps-powershell –

+0

@AUSTX_RJL - 데스크톱에서 ServerManager를 사용할 수없는 이유는 무엇입니까? – Kev