- 1 year ago
Change Forms Authentication in Feature Delegations in IIS using PowerShell
To change Forms Authentication in Feature Delegations in IIS using PowerShell, you can use the WebAdministration
module, which provides a set of cmdlets for managing IIS.
Here's an example PowerShell script that demonstrates how to change Forms Authentication in Feature Delegations in IIS:
powershellImport-Module WebAdministration
# Specify the name of the IIS site
$siteName = "Default Web Site"
# Get the site object
$site = Get-WebSite $siteName
# Set the authentication mode for Forms Authentication
$authConfig = $site.limits | Select-Object -ExpandProperty properties | Where-Object {$_.name -eq "authenticationMode"}
$authConfig.value = "Forms"
# Save the changes to the configuration file
Set-WebConfigurationProperty -filter /system.web/authentication -name mode -value "Forms"
# Enable Forms Authentication in Feature Delegations
$featureName = "Authentication - Forms"
Set-WebConfiguration -filter /system.webServer/security/authentication/anonymousAuthentication -value @{enabled="True"} -pspath "IIS:\Sites\$siteName" -Location $featureName
Set-WebConfiguration -filter /system.webServer/security/authentication/windowsAuthentication -value @{enabled="False"} -pspath "IIS:\Sites\$siteName" -Location $featureName
In this script, we first import the WebAdministration
module, which provides the Get-WebSite
, Set-WebConfigurationProperty
, and Set-WebConfiguration
cmdlets.
We then specify the name of the IIS site we want to modify, and retrieve the site object using the Get-WebSite
cmdlet.
Next, we set the authentication mode for Forms Authentication using the Set-WebConfigurationProperty
cmdlet, and enable Forms Authentication in Feature Delegations using the Set-WebConfiguration
cmdlet.
Note that you may need to modify this script to suit your specific requirements. For example, you may need to specify a different site name, or modify the settings for other authentication methods.
Also, be sure to run the script with administrative privileges, as modifying IIS requires elevated privileges.