How to set application identity of an application pool using web administration module in powershell?

混江龙づ霸主 提交于 2019-12-11 00:52:12

问题


I am using powershell to automate configuring websites in my IIS. I have the following code that creates a web application pool for me

#Creating a new Application Pool
New-WebAppPool "NewAppPool"

How do I go about setting the application pool identity to "Network Service" from my script ?

Please note : There is no IIS Drive on my system. And hence commands which have IIS mentioned in the path like the following fail :

Set-ItemProperty IIS:\AppPools\NewAppPool -name processModel.identityType -value 2

回答1:


When you import the WebAdministration module, PowerShell builds a drive called IIS. This drive allows you to manage IIS just like you would via the file system by simply using IIS: instead of C: to represent the drive.

You can create a Pool like:

    New-Item IIS:\AppPools\$AppPool
    $NewPool = Get-Item IIS:\AppPools\$AppPool
    $NewPool.ProcessModel.Username = "$Username"
    $NewPool.ProcessModel.Password = "$Password"
    $NewPool.ProcessModel.IdentityType = 2
    $NewPool | Set-Item

So for using the below command you have to use the WebAdministration module:

Set-ItemProperty IIS:\AppPools\NewAppPool -name processModel.identityType -value 2

Hope it helps.



来源:https://stackoverflow.com/questions/43246712/how-to-set-application-identity-of-an-application-pool-using-web-administration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!