You don't need separate -PSPath
and -Location
parameters. You can combine them like this:
-PSPath "IIS:\Sites\$SiteName\$AppName"
So the actual command will look like this:
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/windowsAuthentication" -Name Enabled -Value True -PSPath "IIS:\Sites\$SiteName\$AppName"
Note that you may run into this error:
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".
Tomfanning over at ServerFault provided the solution here. I have repeated his steps here:
- Open IIS Manager
- Click the server name in the tree on the left
- Right hand pane, Management section, double click Configuration Editor
- At the top, choose the section system.webServer/security/authentication/anonymousAuthentication
- Right hand pane, click Unlock Section
- At the top, choose the section system.webServer/security/authentication/windowsAuthentication
- Right hand pane, click Unlock Section