आपको मिल-WebConfiguration फोन करके सभी देशी (और साथ ही किसी भी इंस्टॉल किए तीसरे पक्ष के) किसी साइट के लिए रूट वेब अनुप्रयोग के लिए प्रमाणीकरण मोड पुनरावृति कर सकते हैं:
$siteName = "MySiteName"
$authentications = Get-WebConfiguration `
-filter "system.webServer/security/authentication/*" `
-PSPath "IIS:\Sites\$siteName"
तुम भी प्रमाणीकरण मोड पुनरावृति कर सकते हैं साइट पर दिए गए किसी भी वेब एप्लिकेशन के लिए (या यहां तक कि विशिष्ट फ़ाइल भी)।
$authentications = Get-WebConfiguration `
-filter "system.webServer/security/authentication/*" `
-PSPath "IIS:\Sites\$siteName\foo"
SectionPath संपत्ति प्रमाणीकरण मोड जांच करने के लिए इस्तेमाल किया जा सकता है, जैसे:
$authentications | foreach {$_.SectionPath}
कौन सा आउटपुट: निम्नलिखित एक काल्पनिक वेब अनुप्रयोग "\ foo" कहा जाता है के लिए प्रमाणीकरण मोड को पुन: प्राप्त
/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
आपको लगता है कि हो सकता है आप अपने foreach पाश में इस के रूप में सरल कुछ कर सकते हैं ...
$authentications | `
foreach { $_.Enabled = $_.SectionPath.EndsWith('\windowsAuthentication') }
... लेकिन एक समस्या है। यह काम नहीं करता है। यह वास्तव में किसी त्रुटि के साथ असफल नहीं होगा, लेकिन यह कुछ भी नहीं बदलेगा।
ऐसा इसलिए है क्योंकि प्रमाणीकरण अनुभाग लॉक हैं। एक बंद अनुभाग में एक सेटिंग बदलने के लिए, आप सेट-WebConfigurationProperty कॉल करने के लिए की जरूरत है और -Location पैरामीटर, जैसे,
Set-WebConfigurationProperty `
-filter "/system.webServer/security/authentication/windowsAuthentication" `
-name enabled -value true -PSPath "IIS:\" -location $siteName
मुझे लगता है आप अभी भी पाइप foreach-वस्तु cmdlet के लिए वस्तुओं कर सकते हैं शामिल हैं, लेकिन यह शायद हो रहा है यदि आप फ़ोरैच लूप का उपयोग करके इसे स्क्रिप्ट करते हैं तो पढ़ने के लिए बहुत आसान होना (और बनाए रखना) होना चाहिए।
$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
}