Click here to Skip to main content
13,704,533 members
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

1.3K views
2 bookmarked
Posted 13 Aug 2018
Licenced CPOL

Reset username and password of IIS Server Application Pool

, 13 Aug 2018
Rate this:
Please Sign up or sign in to vote.
How to reset username and password of IIS Server Application Pool

There are chances that we need to get Application Pools user name and password for further modifications such as refreshing account or changing password for the users.

The below PowerShell Script will loop through all the App Pools (excluding defaults) and will reset the same user and password again. Scripts can be easily customized to use to update password when a change occurs.

# Check if appcmd.exe exists in default path
if (Test-Path  ("c:\windows\system32\inetsrv\appcmd.exe")) {    

	# Set AppCmd.exe path in variable for further usage.
    $AppCmdPath = 'c:\windows\system32\inetsrv\appcmd.exe'
	
    # Get list of application pools
    & $AppCmdPath list apppools /text:name | 
        ForEach-Object { 
                    
        #Get application pool name
        $PoolName = $_
        
        #Exclude inbuild Application Pools
        if(
        $PoolName -eq "DefaultAppPool" -Or 
        $PoolName -eq "Classic .NET AppPool" -Or 
        $PoolName -eq ".NET v2.0 Classic"-Or
        $PoolName -eq ".NET v2.0"-Or 
        $PoolName -eq ".NET v4.5 Classic" -Or
        $PoolName -eq ".NET v4.5"
        ){
            Write-Host  "Inbuild Pool" + $PoolName
        }
        else{
            #Get username                   
            $PoolUserCmd = $AppCmdPath + ' list apppool "' + 
                           $PoolName + '" /text:processmodel.username'
            $PoolUser = invoke-expression $PoolUserCmd 
                                          
            #Get password
            $PoolPasswordCmd = $AppCmdPath + ' list apppool "' + 
                               $PoolName + '" /text:processmodel.password'
            $PoolPassword = invoke-expression $PoolPasswordCmd 

            #Check if credentials exists
            if ($PoolPassword -ne "") {
                           
                #Re-set the app pool with the same credentials             
                & $AppCmdPath set config -section:system.applicationHost/applicationPools 
                "/[name='$($PoolName )'].processModel.identityType:SpecificUser" 
                "/[name='$($PoolName)'].processModel.userName:$($PoolUser)" 
                "/[name='$($PoolName)'].processModel.password:$($PoolPassword)" 
            }
        }        
    }
    # Do IISRESET after re-setting passwords
    & {iisreset}   
}
else {
    Write-Host -Object 'Could not find the appcmd.exe path at default location, 
                        please try at different place.'
}

Please note that the PowerShell script should be executed in Administrative Privilege.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rajneesh Kumar Verma
Architect
India India
Microsoft Certified Solutions Associate - Cloud Platform || MCSD - App Builder || MCSA - Web Applications || Microsoft Community Contributor (MCC)
A fond lover of Microsoft .NET Technologies including ASP.NET MVC, AZURE etc.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04-2016 | 2.8.180920.1 | Last Updated 14 Aug 2018
Article Copyright 2018 by Rajneesh Kumar Verma
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid