Import-Module "WebAdministration"
# Create app pool
$appName = "Test.WebUI"
New-Item IIS:\AppPools\$appName
Set-ItemProperty -Path "IIS:\AppPools\${appName}" -name "managedRuntimeVersion" -value ""
Set-ItemProperty -Path "IIS:\AppPools\${appName}" -name "autoStart" -value $true
Set-ItemProperty -Path "IIS:\AppPools\${appName}" -name "startMode" -value "AlwaysRunning"
# "ApplicationPoolIdentity" = best
# "LocalSysten" = bad idea!
# "NetworkService" = not so bad
# "SpecificUser" = useful if the user needs special rights. See other examples
# below for how to do this.
Set-ItemProperty -Path "IIS:\AppPools\${appName}" -name "processModel" -value @{identitytype="ApplicationPoolIdentity"}
$webSitePath = 'C:\inetpub\' + $appName
$port = 58807
# Create new website
New-Item IIS:\Sites\$appName -physicalPath $webSitePath -bindings @{protocol="http";bindingInformation=":${port}:"}
Set-ItemProperty IIS:\Sites\$appName -name applicationPool -value $appName
多亏了
https://octopus.com/blog/iis-powershell