powershelliisapplication-poolapplicationpoolidentityweb-administration

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


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

Solution

  • 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.