简体   繁体   中英

Powershell - Unable to disable Anonymous Authentication in IIS for a website

When I use the following Powerhell script the anonymous authentification for the my website in IIS is not changing from 'Enabled' to 'Disabled'. Could anybody help please:-

Import-Module WebAdministration

Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value false -PSPath IIS:\Sites\myWebsite -Force

I also tried this:-

    Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name disable -value true -PSPath IIS:\Sites\myWebsite -Force

I have also tried:-

Set-WebConfigurationProperty -filter '/system.webServer/security/authentication/anonymousAuthentication' -name enabled -value false -PSPath IIS:\Sites\myWebsite -Force

I have also tried this but stil does not work:-

Set-WebConfigurationProperty -Filter /system.webServer/security/authentication/anonymousAuthentication -name Enabled -value False -PSPath 'IIS:\' -Location "Sites\myWebsite"

I am not getting any errors. It appears that the script runs successfully.

Also, does anybody know how I would set forms Authentication to disabled too?

So looks like I am able to set the authentication to 'Enabled' if I do this:-

Set-WebConfigurationProperty -Filter /system.webServer/security/authentication/anonymousAuthentication -name Enabled -value true -Location "IIS:\Sites\myWebsite"

But I can not set the Authentication to 'Disabled' if I do this:-

Set-WebConfigurationProperty -Filter /system.webServer/security/authentication/anonymousAuthentication -name Enabled -value false -Location "IIS:\Sites\myWebsite"

好的,我有解决方案:-

Set-WebConfiguration system.webServer/security/authentication/anonymousAuthentication -PSPath IIS:\ -Location myWebsite -Value @{enabled="True"}
Import-Module WebAdministration
Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name enabled -value false -PSPath IIS:\\ -location ${site_name}/${virtual_directory_name}

This should do what you want. Ran with enabled values of both true and false and verified in IIS.

This will surely work just check your IIS path correctly..

Import-Module WebAdministration
Set-WebConfigurationProperty -filter /system.WebServer/security/authentication/AnonymousAuthentication -name enabled -value false -location "IIS:\Sites\Default Web Site\NMFD"

In case non of above worked and if someone is still looking for answer this worked for me

Set-WebConfigurationProperty -Filter '/system.webServer/security/authentication/anonymousAuthentication' -Name enabled -Value False -PSPath 'MACHINE/WEBROOT/APPHOST/Default Web Site'

Basically I took PSPath from below command

Get-WebConfiguration -filter /system.webServer/security/authentication/anonymousAuthentication 'iis:\sites\Default Web Site' |select *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM