Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

Commit 864b478

Browse files
Leave checking if the app pool exists for a later example
1 parent 0a7ded9 commit 864b478

File tree

2 files changed

+98
-106
lines changed

2 files changed

+98
-106
lines changed

‎examples/04-CreateAppPool/IIS.ps1

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,43 @@ cd $here
1111
# -----------------------------------------------------------------------------
1212
Import-Module IISAdministration
1313

14-
$pool = Get-IISAppPool -Name "My Pool" -WarningAction SilentlyContinue
15-
if ($pool -eq $null) {
16-
$manager = Get-IISServerManager
17-
$pool = $manager.ApplicationPools.Add("My Pool")
14+
$manager = Get-IISServerManager
15+
$pool = $manager.ApplicationPools.Add("My Pool")
1816

19-
# Older applications may require "Classic" mode, but most modern ASP.NET
20-
# apps use the integrated pipeline
21-
$pool.ManagedPipelineMode = "Integrated"
17+
# Older applications may require "Classic" mode, but most modern ASP.NET
18+
# apps use the integrated pipeline
19+
$pool.ManagedPipelineMode = "Integrated"
2220

23-
# What version of the .NET runtime to use. Valid options are "v2.0" and
24-
# "v4.0". IIS Manager often presents them as ".NET 4.5", but these still
25-
# use the .NET 4.0 runtime so should use "v4.0". For a "No Managed Code"
26-
# equivalent, pass an empty string.
27-
$pool.ManagedRuntimeVersion = "v4.0"
21+
# What version of the .NET runtime to use. Valid options are "v2.0" and
22+
# "v4.0". IIS Manager often presents them as ".NET 4.5", but these still
23+
# use the .NET 4.0 runtime so should use "v4.0". For a "No Managed Code"
24+
# equivalent, pass an empty string.
25+
$pool.ManagedRuntimeVersion = "v4.0"
2826

29-
# If your ASP.NET app must run as a 32-bit process even on 64-bit machines
30-
# set this to $true. This is usually only important if your app depends
31-
# on some unmanaged (non-.NET) DLL's.
32-
$pool.Enable32BitAppOnWin64 = $false
27+
# If your ASP.NET app must run as a 32-bit process even on 64-bit machines
28+
# set this to $true. This is usually only important if your app depends
29+
# on some unmanaged (non-.NET) DLL's.
30+
$pool.Enable32BitAppOnWin64 = $false
3331

34-
# Starts the application pool automatically when a request is made. If you
35-
# set this to false, you have to manually start the application pool or
36-
# you will get 503 errors.
37-
$pool.AutoStart = $true
32+
# Starts the application pool automatically when a request is made. If you
33+
# set this to false, you have to manually start the application pool or
34+
# you will get 503 errors.
35+
$pool.AutoStart = $true
3836

39-
# "AlwaysRunning" = application pool loads when Windows starts, stays running
40-
# even when the application/site is idle.
41-
# "OnDemand" = IIS starts it when needed. If there are no requests, it may
42-
# never be started.
43-
$pool.StartMode = "OnDemand"
37+
# "AlwaysRunning" = application pool loads when Windows starts, stays running
38+
# even when the application/site is idle.
39+
# "OnDemand" = IIS starts it when needed. If there are no requests, it may
40+
# never be started.
41+
$pool.StartMode = "OnDemand"
4442

45-
# What account does the application pool run as?
46-
# "ApplicationPoolIdentity" = best
47-
# "LocalSysten" = bad idea!
48-
# "NetworkService" = not so bad
49-
# "SpecificUser" = useful if the user needs special rights
50-
$pool.ProcessModel.IdentityType = "ApplicationPoolIdentity"
43+
# What account does the application pool run as?
44+
# "ApplicationPoolIdentity" = best
45+
# "LocalSysten" = bad idea!
46+
# "NetworkService" = not so bad
47+
# "SpecificUser" = useful if the user needs special rights
48+
$pool.ProcessModel.IdentityType = "ApplicationPoolIdentity"
5149

52-
$manager.CommitChanges()
53-
}
50+
$manager.CommitChanges()
5451

5552
# -----------------------------------------------------------------------------
5653
# Assert

‎examples/04-CreateAppPool/Web.ps1

Lines changed: 68 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,84 @@ cd $here
1212

1313
Import-Module WebAdministration
1414

15-
if ((Test-Path "IIS:\AppPools\My Pool 3") -eq $False) {
16-
New-Item -Path "IIS:\AppPools" -Name "My Pool 3" -Type AppPool
17-
18-
Write-Host "Managed pipeline mode:"
19-
Get-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "managedPipelineMode"
20-
21-
# What version of the .NET runtime to use. Valid options are "v2.0" and
22-
# "v4.0". IIS Manager often presents them as ".NET 4.5", but these still
23-
# use the .NET 4.0 runtime so should use "v4.0". For a "No Managed Code"
24-
# equivalent, pass an empty string.
25-
Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "managedRuntimeVersion" -value "v4.0"
26-
27-
# If your ASP.NET app must run as a 32-bit process even on 64-bit machines
28-
# set this to $true. This is usually only important if your app depends
29-
# on some unmanaged (non-.NET) DLL's.
30-
Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "enable32BitAppOnWin64" -value $false
31-
32-
# Starts the application pool automatically when a request is made. If you
33-
# set this to false, you have to manually start the application pool or
34-
# you will get 503 errors.
35-
Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "autoStart" -value $true
36-
37-
# What account does the application pool run as?
38-
# "ApplicationPoolIdentity" = best
39-
# "LocalSysten" = bad idea!
40-
# "NetworkService" = not so bad
41-
# "SpecificUser" = useful if the user needs special rights. See other examples
42-
# below for how to do this.
43-
Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "processModel" -value @{identitytype="ApplicationPoolIdentity"}
44-
45-
# Older applications may require "Classic" mode, but most modern ASP.NET
46-
# apps use the integrated pipeline.
47-
#
48-
# On newer versions of PowerShell, setting the managedPipelineMode is easy -
49-
# just use a string:
50-
#
51-
# Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" `
52-
# -name "managedPipelineMode" `
53-
# -value "Integrated"
54-
#
55-
# However, the combination of PowerShell and the IIS module in Windows
56-
# Server 2008 and 2008 R2 requires you to specify the value as an integer.
57-
#
58-
# 0 = Integrated
59-
# 1 = Classic
60-
#
61-
# If you hate hard-coding magic numbers you can do this (or use the string
62-
# if 2008 support isn't an issue for you):
63-
#
64-
# Add-Type -Path "${env:SystemRoot}\System32\inetsrv\Microsoft.Web.Administration.dll"
65-
# $pipelineMode = [Microsoft.Web.Administration.ManagedPipelineMode]::Integrated
66-
# Set-ItemProperty -Path "..." -name "managedPipelineMode" -value ([int]$pipelineMode)
67-
#
68-
# If this DLL doesn't exist, you'll need to install the IIS Management
69-
# Console role service.
70-
Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "managedPipelineMode" -value 0
71-
72-
# This setting was added in IIS 8. It's different to autoStart (which means
73-
# "start the app pool when a request is made") in that it lets you keep
74-
# an app pool running at all times even when there are no requests.
75-
# Since it was added in IIS 8 you may need to check the OS version before
76-
# trying to set it.
77-
#
78-
# "AlwaysRunning" = application pool loads when Windows starts, stays running
79-
# even when the application/site is idle.
80-
# "OnDemand" = IIS starts it when needed. If there are no requests, it may
81-
# never be started.
82-
if ([Environment]::OSVersion.Version -ge (new-object 'Version' 6,2)) {
83-
Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "startMode" -value "OnDemand"
84-
}
15+
New-Item -Path "IIS:\AppPools" -Name "My Pool" -Type AppPool
16+
17+
# What version of the .NET runtime to use. Valid options are "v2.0" and
18+
# "v4.0". IIS Manager often presents them as ".NET 4.5", but these still
19+
# use the .NET 4.0 runtime so should use "v4.0". For a "No Managed Code"
20+
# equivalent, pass an empty string.
21+
Set-ItemProperty -Path "IIS:\AppPools\My Pool" -name "managedRuntimeVersion" -value "v4.0"
22+
23+
# If your ASP.NET app must run as a 32-bit process even on 64-bit machines
24+
# set this to $true. This is usually only important if your app depends
25+
# on some unmanaged (non-.NET) DLL's.
26+
Set-ItemProperty -Path "IIS:\AppPools\My Pool" -name "enable32BitAppOnWin64" -value $false
27+
28+
# Starts the application pool automatically when a request is made. If you
29+
# set this to false, you have to manually start the application pool or
30+
# you will get 503 errors.
31+
Set-ItemProperty -Path "IIS:\AppPools\My Pool" -name "autoStart" -value $true
32+
33+
# What account does the application pool run as?
34+
# "ApplicationPoolIdentity" = best
35+
# "LocalSysten" = bad idea!
36+
# "NetworkService" = not so bad
37+
# "SpecificUser" = useful if the user needs special rights. See other examples
38+
# below for how to do this.
39+
Set-ItemProperty -Path "IIS:\AppPools\My Pool" -name "processModel" -value @{identitytype="ApplicationPoolIdentity"}
40+
41+
# Older applications may require "Classic" mode, but most modern ASP.NET
42+
# apps use the integrated pipeline.
43+
#
44+
# On newer versions of PowerShell, setting the managedPipelineMode is easy -
45+
# just use a string:
46+
#
47+
# Set-ItemProperty -Path "IIS:\AppPools\My Pool 3" `
48+
# -name "managedPipelineMode" `
49+
# -value "Integrated"
50+
#
51+
# However, the combination of PowerShell and the IIS module in Windows
52+
# Server 2008 and 2008 R2 requires you to specify the value as an integer.
53+
#
54+
# 0 = Integrated
55+
# 1 = Classic
56+
#
57+
# If you hate hard-coding magic numbers you can do this (or use the string
58+
# if 2008 support isn't an issue for you):
59+
#
60+
# Add-Type -Path "${env:SystemRoot}\System32\inetsrv\Microsoft.Web.Administration.dll"
61+
# $pipelineMode = [Microsoft.Web.Administration.ManagedPipelineMode]::Integrated
62+
# Set-ItemProperty -Path "..." -name "managedPipelineMode" -value ([int]$pipelineMode)
63+
#
64+
# If this DLL doesn't exist, you'll need to install the IIS Management
65+
# Console role service.
66+
Set-ItemProperty -Path "IIS:\AppPools\My Pool" -name "managedPipelineMode" -value 0
67+
68+
# This setting was added in IIS 8. It's different to autoStart (which means
69+
# "start the app pool when a request is made") in that it lets you keep
70+
# an app pool running at all times even when there are no requests.
71+
# Since it was added in IIS 8 you may need to check the OS version before
72+
# trying to set it.
73+
#
74+
# "AlwaysRunning" = application pool loads when Windows starts, stays running
75+
# even when the application/site is idle.
76+
# "OnDemand" = IIS starts it when needed. If there are no requests, it may
77+
# never be started.
78+
if ([Environment]::OSVersion.Version -ge (new-object 'Version' 6,2)) {
79+
Set-ItemProperty -Path "IIS:\AppPools\My Pool" -name "startMode" -value "OnDemand"
8580
}
8681

8782
# -----------------------------------------------------------------------------
8883
# Assert
8984
# -----------------------------------------------------------------------------
9085

91-
if ((Get-WebAppPoolState -Name "My Pool 3") -eq $null) { Write-Error "Website1 not found" }
92-
if ((Get-ItemProperty -Path "IIS:\AppPools\My Pool 3" -name "managedPipelineMode") -ne "Integrated") { Write-Error "Wrong pipeline mode" }
86+
if ((Get-WebAppPoolState -Name "My Pool") -eq $null) { Write-Error "Website1 not found" }
87+
if ((Get-ItemProperty -Path "IIS:\AppPools\My Pool" -name "managedPipelineMode") -ne "Integrated") { Write-Error "Wrong pipeline mode" }
9388

9489
# -----------------------------------------------------------------------------
9590
# Clean up
9691
# -----------------------------------------------------------------------------
9792

9893
. ..\_Teardown.Web.ps1
9994

100-
Remove-Item -Path "IIS:\AppPools\My Pool 3" -Recurse -Force
95+
Remove-Item -Path "IIS:\AppPools\My Pool" -Recurse -Force

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /