0

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"
ED209
  • 588
  • 1
  • 9
  • 26
  • not sure this will work but maybe try wrapping your filter in single quotes? small possibility that it's reading the `/` as an escape char. – Mike Garuccio Nov 30 '16 at 15:04
  • Hi Mike. Thanks for helping, but unfortunately this did not work :-(. – ED209 Nov 30 '16 at 15:11
  • can you try to write False instead of false – Martin Brandl Nov 30 '16 at 18:32
  • or this: `Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/anonymousAuthentication" -Name Enabled -Value False -PSPath IIS:\ -Location "Sites\myWebsite"` – Martin Brandl Nov 30 '16 at 18:35
  • Hi Martin I tried what you suggested but got an error. – ED209 Dec 01 '16 at 06:28
  • Set-WebConfigurationProperty : Filename: Error: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/Sites\myWebsite' At C:\Users\andrew.short\Documents\Software\Power Shell\Untitled11.ps1:16 char:29+ Set-WebConfigurationProperty <<<< -Filtersystem.webServer/security/authentication/anonymousAuthentication -name Enabled -value False -PSPath 'IIS:\' -Location"Sites\myWebsite" + CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], FileNotFoundException+ FullyQualifiedErrorId :System.IO.FileNotFoundException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand – ED209 Dec 01 '16 at 06:30

4 Answers4

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

BrianH
  • 1,082
  • 1
  • 16
  • 23
0

Ok I have the solution:-

Set-WebConfiguration system.webServer/security/authentication/anonymousAuthentication -PSPath IIS:\ -Location myWebsite -Value @{enabled="True"}
ED209
  • 588
  • 1
  • 9
  • 26
  • For me this doesn't work as IIS asks for a 'name' for the parameter. I set this to -Name Enabled but then get the same error as above. – GrahamJ Jun 19 '17 at 14:32
0

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"
0

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 *
Dhiraj
  • 613
  • 6
  • 25
  • This gives: `Set-WebConfigurationProperty : This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".` – Robin Jul 20 '22 at 11:04
  • Are you sure you have all required IIS features turned on in your windows server? – Dhiraj Sep 23 '22 at 12:32