Score:0

Remove attributes from IIS applicationHost using WebAdministration module

my flag

In IIS, the physical path credentials are set in applicationHost.config like so:

<virtualDirectory path="/" physicalPath="C:\Path\to\files" userName="user" password="[enc:IISCngProvider:ENCRYPTEDBLOBHERE=:enc]" />

To set or change the value of userName and password, I can use Set-WebConfigurationProperty:

$xpath = "system.applicationhost/sites/site[@name='Default Web Site']/application[@path='/MyApplication']/virtualDirectory[@path='/']"
Set-WebConfigurationProperty $xpath -name userName -value "USERNAME"
Set-WebConfigurationProperty $xpath -name password -value "PASSWORD"

But how do I remove those attributes, so IIS switches back to using pass-through authentication? I've tried all of the following with no success:

Remove-WebConfigurationProperty $xpath -name userName
# Property name userName doesn't point to collection.

Remove-WebConfigurationProperty "$xpath/@userName"
# The Name parameter is required

Remove-WebConfigurationProperty "$xpath/@userName" -name .
# WARNING: Property . is not found on  /system.applicationHost/sites/site[@name='Default Web Site' and @id='1']/application[@path='/MyApplication']/virtualDirectory[@path='/']/@userName.

Clear-WebConfiguration "$xpath/@userName" -Force
# Nothing appears to change

Remove-ItemProperty "IIS:\Sites\Default Web Site\MyApplication" -Name userName
# Property name userName doesn't point to collection.

I know I can do this with appcmd, but shouldn't there be a way to do this with the WebAdministration module?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.