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 f8b16de

Browse files
Add example for changing physical paths
1 parent 06086c4 commit f8b16de

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

‎examples/07-ChangePaths/IIS.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -----------------------------------------------------------------------------
2+
# Setup
3+
# -----------------------------------------------------------------------------
4+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
cd $here
6+
7+
. ..\_Setup.IIS.ps1
8+
9+
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10+
mkdir "C:\Sites\Website11円.0" -ErrorAction SilentlyContinue
11+
mkdir "C:\Sites\Website11円.1" -ErrorAction SilentlyContinue
12+
13+
$manager = Get-IISServerManager
14+
$manager.ApplicationPools.Add("My Pool")
15+
$manager.Sites.Add("Website1", "http", "*:8022:", "C:\Sites\Website1")
16+
$manager.Sites["Website1"].Applications.Add("/MyApp", "C:\Sites\MyApp")
17+
$manager.CommitChanges()
18+
19+
# -----------------------------------------------------------------------------
20+
# Example
21+
# -----------------------------------------------------------------------------
22+
Import-Module IISAdministration
23+
24+
$manager = Get-IISServerManager
25+
26+
# Remember, in the IIS Administration view of the world, sites contain
27+
# applications, and applications contain virtual directories, and it is
28+
# virtual directories that point at a physical path on disk.
29+
30+
# Change for a top-level website
31+
$manager.Sites["Website1"].Applications["/"].VirtualDirectories["/"].PhysicalPath = "C:\Sites\Website11円.1"
32+
33+
# Change for an app within a website
34+
$manager.Sites["Website1"].Applications["/MyApp"].VirtualDirectories["/"].PhysicalPath = "C:\Sites\Website11円.1"
35+
36+
$manager.CommitChanges()
37+
38+
# -----------------------------------------------------------------------------
39+
# Assert
40+
# -----------------------------------------------------------------------------
41+
if ($manager.Sites["Website1"].Applications["/"].VirtualDirectories["/"].PhysicalPath -ne "C:\Sites\Website11円.1") { Write-Error "Our logic is wrong" }
42+
43+
# -----------------------------------------------------------------------------
44+
# Clean up
45+
# -----------------------------------------------------------------------------
46+
47+
. ..\_Teardown.IIS.ps1
48+
49+
Remove-IISSite -Name "Website1" -Confirm:$false
50+
51+
$manager = Get-IISServerManager
52+
$manager.ApplicationPools["My Pool"].Delete()
53+
$manager.CommitChanges()

‎examples/07-ChangePaths/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
### Change physical path of a site or application
2+
3+
When deploying a new version of an application, my preference (and the way Octopus Deploy works) is to deploy to a fresh, new folder on disk, then update IIS to point to it. So you begin with:
4+
5+
C:\Sites\Website11円.0 <--- IIS points here
6+
7+
You deploy the new version:
8+
9+
C:\Sites\Website11円.0 <--- IIS points here
10+
C:\Sites\Website11円.1
11+
12+
You can then make any necessary changes to configuration files, etc. and then update IIS to point to it:
13+
14+
C:\Sites\Website11円.0
15+
C:\Sites\Website11円.1 <--- Now IIS points here
16+
17+
Should you ever need to roll back in a hurry, you can leave the old folder on disk and point back to it:
18+
19+
C:\Sites\Website11円.0 <--- IIS points here (we rolled back manually)
20+
C:\Sites\Website11円.1

‎examples/07-ChangePaths/Web.ps1

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -----------------------------------------------------------------------------
2+
# Setup
3+
# -----------------------------------------------------------------------------
4+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
cd $here
6+
7+
. ..\_Setup.Web.ps1
8+
9+
mkdir "C:\Sites\Website1" -ErrorAction SilentlyContinue
10+
mkdir "C:\Sites\Website11円.0" -ErrorAction SilentlyContinue
11+
mkdir "C:\Sites\Website11円.1" -ErrorAction SilentlyContinue
12+
mkdir "C:\Sites\MyApp" -ErrorAction SilentlyContinue
13+
14+
New-Item -Path "IIS:\AppPools" -Name "My Pool" -Type AppPool
15+
New-Website -Name "Website1" -Port 80 -IPAddress "*" -HostHeader "" -PhysicalPath "C:\Sites\Website1"
16+
New-Item -Type Application -Path "IIS:\Sites\Website1\MyApp" -physicalPath "C:\Sites\MyApp"
17+
18+
# -----------------------------------------------------------------------------
19+
# Example
20+
# -----------------------------------------------------------------------------
21+
22+
Import-Module WebAdministration
23+
24+
# The pattern here is to use Test-Path with the IIS:\ drive provider
25+
26+
Set-ItemProperty -Path "IIS:\Sites\Website1" -name "physicalPath" -value "C:\Sites\Website11円.1"
27+
Set-ItemProperty -Path "IIS:\Sites\Website1\MyApp" -name "physicalPath" -value "C:\Sites\Website11円.1"
28+
29+
# -----------------------------------------------------------------------------
30+
# Assert
31+
# -----------------------------------------------------------------------------
32+
33+
if ((Get-ItemProperty -Path "IIS:\Sites\Website1" -name "physicalPath") -ne "C:\Sites\Website11円.1") { Write-Error "Our logic is wrong" }
34+
35+
# -----------------------------------------------------------------------------
36+
# Clean up
37+
# -----------------------------------------------------------------------------
38+
39+
. ..\_Teardown.Web.ps1
40+
41+
Remove-Item -Path "IIS:\Sites\Website1" -Recurse -Force
42+
Remove-Item -Path "IIS:\AppPools\My Pool" -Recurse -Force

0 commit comments

Comments
(0)

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