简体   繁体   中英

changing IIS site physical path credentials to apppool idenity with a script

I have a webserver with many websites on it.

They are currently using an administrator account for physical path credentials, which is less than ideal.

I have added a user for every single site and set the appropriate permissions etc. I have also gone through and changed the app pool user for each application pool.

What i need to do now is change the physical path credentials for every site to use the 'Application User'.

I've used the following script before to change a specific sites credentials to a specific user, but not sure how this would change to become the application user...

 appcmd set site "mywebsite.co.uk" -virtualDirectoryDefaults.userName:mywebsite_co_uk -virtualDirectoryDefaults.password:AbCdEfGh!1

Any help is greatly appriciated :)

If I understand correctly, it sounds like you have previously used "credentials" at the site level to connect to read the content, and now you are using application pool configured with isolated credentials (much better approach) and want to now set the sites to use that identity instead of the previously setup ones. To do that you just need to clear the credentials in the site that were there before, you can do that with the following appcmd.exe command line (this example is clearing the "default web site" so just change that as needed)

appcmd.exe clear config -section:system.applicationHost/sites /"[name='Default Web Site'].[path='/'].[path='/'].userName" /"[name='Default Web Site'].[path='/'].[path='/'].password" /commit:apphost

In your case above, it seems you were setting it in the "defaults" section (probably not the right thing, and should have set it at the root one instead), but to clear that one you need to use a command line like this:

appcmd.exe clear config -section:system.applicationHost/sites /"[name='Default Web Site'].virtualDirectoryDefaults.userName" /"[name='Default Web Site'].virtualDirectoryDefaults.password" /commit:apphost

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