Skip to content

How to Create an IIS Website and Application Pool with PowerShell Print

  • 0

Applies to: Windows Server 2019, Windows Server 2022 and Windows Server 2025, subject to the workload and edition requirements below.

Separate the website, application pool and content directory

An IIS website defines bindings and the application hierarchy exposed through them. An application pool supplies the worker-process boundary and runtime settings. The content directory holds the deployed files. Keeping these separate lets you assign a site a dedicated process identity and recycle or troubleshoot it without unnecessarily affecting other sites. Creating a website does not automatically give its worker process the right file permissions or install its application framework.

This example creates a small static Portal site with its own PortalPool, an explicit host header and a staging HTTP port. It is a controlled readiness test, not a public production deployment. A framework application needs its supported runtime, handler and pool settings. HTTPS, authentication, deployment permissions and backup are completed as separate deliberate steps before production use.

Check names, ports and existing IIS configuration

Use elevated Windows PowerShell 5.1 with the WebAdministration module on a server where IIS and static-content support are installed. Inspect existing websites and pools before creating objects. Reusing a production name or an overlapping binding can make a new site fail to start or direct requests to the wrong application.

Import-Module WebAdministration
Get-Website | Select-Object Name,Id,State,PhysicalPath,Bindings
Get-ChildItem IIS:\AppPools | Select-Object Name,State
Get-WebBinding
Get-NetTCPConnection -State Listen -LocalPort 8080 -ErrorAction SilentlyContinue

Choose a site name, pool name, approved content volume and DNS hostname. Port 8080 is used here to keep the test distinct from an existing port-80 site, but another process could already use it. A host-header binding selects a site; it is not an authentication control. Scope any firewall exposure to the approved test clients and do not publish staging content through an upstream proxy accidentally.

Back up global IIS configuration with AppCmd before modifying a shared server. Preserve content separately because that backup does not include the application files. Record the previous bindings and runtime settings of any objects that will actually be changed.

Create the dedicated pool with a matching runtime policy

Create PortalPool before granting its virtual identity file access. For this static-content example, No Managed Code is appropriate, represented by an empty managedRuntimeVersion. A classic ASP.NET Framework application commonly requires v4.0, while ASP.NET Core uses its hosting module and its own runtime. Do not apply the static example’s runtime selection blindly to another application.

New-WebAppPool -Name 'PortalPool'
Set-ItemProperty 'IIS:\AppPools\PortalPool' -Name managedRuntimeVersion -Value ''
Set-ItemProperty 'IIS:\AppPools\PortalPool' -Name processModel.identityType -Value ApplicationPoolIdentity
Get-Item 'IIS:\AppPools\PortalPool' |
  Select-Object Name,managedRuntimeVersion,managedPipelineMode

ApplicationPoolIdentity provides a distinct virtual identity for the pool and avoids managing a custom password for this local static site. Review recycling, idle timeout, 32-bit mode and startup behaviour against the real application later. Increasing worker-process counts or disabling recycling is not a default performance improvement. Keep one clear initial process boundary so failures and permissions remain understandable.

Prepare an empty content folder and read-only runtime access

Create a new reviewed directory on the intended data volume. Do not overwrite an existing application to make a test page. The following New-Item command is expected to fail if Portal already exists, prompting inspection rather than silently reusing unknown content. Retain administrator and SYSTEM access and review inherited entries before publishing.

$path = 'D:\Sites\Portal'
New-Item -ItemType Directory -Path $path -ErrorAction Stop | Out-Null
Set-Content -LiteralPath ($path + '\index.html') `
  -Value '<!doctype html><title>Portal readiness</title><p>Portal staging response.</p>' `
  -Encoding UTF8
icacls $path /grant:r 'IIS AppPool\PortalPool:(OI)(CI)RX'
icacls $path

The pool receives read and execute, not Modify or Full Control. If an application later needs uploads or data writes, grant only the designated data directory and consider keeping it outside executable content. A deployment account and a runtime account have different responsibilities. Do not grant IIS_IUSRS broad write access across every site simply to avoid understanding which pool owns a permission failure.

Create the binding and align anonymous identity

Create the site with an explicit application pool, path, host header and staging port. The example intentionally uses Anonymous Authentication for a harmless static test page. Configure its anonymous identity to use the pool so the ACL granted above is the identity actually reading the file. A production application may require a different authentication model.

New-Website -Name 'Portal' -PhysicalPath $path -ApplicationPool 'PortalPool' `
  -IPAddress '*' -Port 8080 -HostHeader 'portal.corp.example'
Set-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Location 'Portal' `
  -Filter 'system.webServer/security/authentication/anonymousAuthentication' `
  -Name userName -Value ''
Get-WebBinding -Name 'Portal'
Get-WebAppPoolState -Name 'PortalPool'

Check that the binding is unique and that the site is started. An IP wildcard means all suitable server addresses, so use a specific approved local IP when the design needs that boundary. Do not confuse anonymous content identity with the worker-process identity: the default IUSR choice can otherwise make a pool ACL look ineffective. Configuration locking may require a server-level change by the appropriate administrator rather than editing web.config.

Verify the exact site and expected content

Test locally with the intended Host header so the request selects Portal rather than another site. Then test from an approved client using the intended DNS name and staging port. Inspect the returned body and status; a 200 response from the wrong site is not success.

$response = Invoke-WebRequest -Uri 'http://127.0.0.1:8080/' `
  -Headers @{Host='portal.corp.example'} -UseBasicParsing
$response.StatusCode
$response.Content
Get-Website -Name 'Portal' | Select-Object Name,Id,State,PhysicalPath
Get-WebBinding -Name 'Portal'

Expect the specific Portal staging response and a successful status. Verify that the request appears in the log for Portal’s site ID, allowing for buffering. A remote TCP test confirms reachability but should be followed by an HTTP request with the correct hostname. Test that unapproved networks cannot reach the staging listener if the boundary relies on firewall scope. Keep test content free of secrets, environment variables and diagnostic stack traces.

Diagnose common site and pool failures

For a binding conflict, inspect all site bindings and the actual listener rather than changing ports randomly. For 403.14, confirm index.html is present and default-document support is installed; do not enable directory browsing as a general remedy. For 401 or file-access errors, identify the anonymous and pool identities and inspect the actual file ACL, including disabled inheritance on a child object.

For 503, check whether PortalPool stopped or rapid-fail protection disabled it after repeated worker failures. Inspect WAS, W3SVC and application events before restarting it repeatedly. A 500.19 configuration error should include a specific file, line and error code; use those to distinguish malformed configuration, a locked section or a missing module. If static content succeeds but the application fails, review its runtime and handler requirements rather than granting more file privileges.

Rollback objects separately and finish the production design

If this new pilot is abandoned, stop Portal, preserve any needed evidence and remove only the new website and unused pool. Remove-Website does not decide whether the physical directory is disposable, and Remove-WebAppPool should not be used while another application references it. Delete the test content only after checking that no real data was added.

Before promoting the application, replace the staging binding with the approved HTTPS plan, install and validate the real application, review authentication and authorization, define log retention and monitoring, and configure backups for code, data, configuration and certificates. Record the site-to-pool relationship and runtime permissions. A dedicated pool is valuable isolation, but it must be paired with deliberate file access and a recoverable deployment to provide a reliable hosting boundary.

Related guidance and official references

Install IIS; Configure an HTTPS certificate; Use a custom application pool identity; Back up IIS configuration.


Was this answer helpful?

« Back