Sen-WebConfiguration alın arayarak tüm yerli (yanı sıra herhangi bir yüklü üçüncü taraf) bir sitenin kök web uygulaması için kimlik doğrulama modları yineleyebilirsiniz:
$siteName = "MySiteName"
$authentications = Get-WebConfiguration `
-filter "system.webServer/security/authentication/*" `
-PSPath "IIS:\Sites\$siteName"
Ayrıca kimlik doğrulama modları yineleme yapabilirsiniz Sitede verilen herhangi bir web uygulaması için (veya belirli dosya (lar)). SectionPath mülkiyet kimlik doğrulama modunu incelemek için kullanılabilir
$authentications = Get-WebConfiguration `
-filter "system.webServer/security/authentication/*" `
-PSPath "IIS:\Sites\$siteName\foo"
, örneğin:
$authentications | foreach {$_.SectionPath}
verir: Aşağıdaki "\ foo" adlı bir yapmacık bir web uygulaması için kimlik doğrulama modları alır
/system.webServer/security/authentication/digestAuthentication
/system.webServer/security/authentication/anonymousAuthentication
/system.webServer/security/authentication/iisClientCertificateMappingAuthentication
/system.webServer/security/authentication/basicAuthentication
/system.webServer/security/authentication/clientCertificateMappingAuthentication
/system.webServer/security/authentication/windowsAuthentication
size foreach döngüsünde bu kadar basit bir şeyi yapabileceğini düşünebilir
...
$authentications | `
foreach { $_.Enabled = $_.SectionPath.EndsWith('\windowsAuthentication') }
... ama bir problem var. Çalışmıyor. Aslında bir hata ile başarısız olmaz, ama hiçbir şey değişmez. Bu, kimlik doğrulama bölümlerinin kilitlenmesi nedeniyle olur. Kilitli bir bölümünde bir ayarı değiştirmek için, Set-WebConfigurationProperty için gerekli fiziksel -Yer parametreyi, örneğin
Set-WebConfigurationProperty `
-filter "/system.webServer/security/authentication/windowsAuthentication" `
-name enabled -value true -PSPath "IIS:\" -location $siteName
Sana boru foreach-nesne cmdlet'ine nesneleri yine de varsayalım dahil ama muhtemelen gidiyor Bunu bir foreach döngüsü kullanarak beterseniz çok daha kolay okunabilir (ve devam ettirilebilir).
$siteName = "MySiteName"
$authentications = Get-WebConfiguration `
-filter "system.webServer/security/authentication/*" `
-PSPath "IIS:\Sites\$siteName"
foreach ($auth in $authentications)
{
$auth.SectionPath -match "/windowsAuthentication$"
$enable = ($matches.count -gt 0)
Set-WebConfigurationProperty `
-filter $auth.SectionPath `
-name enabled -value $enable -PSPath "IIS:\" -location $siteName
}