|
| 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 | + |
| 11 | +$manager = Get-IISServerManager |
| 12 | +$manager.ApplicationPools.Add("My Pool") |
| 13 | +$manager.Sites.Add("Website1", "http", "*:8022:", "C:\Sites\Website1") |
| 14 | +$manager.Sites["Website1"].Applications.Add("/MyApp", "C:\Sites\MyApp") |
| 15 | +$manager.CommitChanges() |
| 16 | + |
| 17 | +# ----------------------------------------------------------------------------- |
| 18 | +# Example |
| 19 | +# ----------------------------------------------------------------------------- |
| 20 | +Import-Module IISAdministration |
| 21 | + |
| 22 | +$manager = Get-IISServerManager |
| 23 | + |
| 24 | +# The pattern here is to get the things you want, then check if they are null |
| 25 | + |
| 26 | +if ($manager.ApplicationPools["My Pool"] -eq $null) { |
| 27 | + # Application pool does not exist, create it... |
| 28 | + # ... |
| 29 | +} |
| 30 | + |
| 31 | +if ($manager.Sites["Website1"] -eq $null) { |
| 32 | + # Site does not exist, create it... |
| 33 | + # ... |
| 34 | +} |
| 35 | + |
| 36 | +if ($manager.Sites["Website1"].Applications["/MyApp"] -eq $null) { |
| 37 | + # App/virtual directory does not exist, create it... |
| 38 | + # ... |
| 39 | +} |
| 40 | + |
| 41 | +$manager.CommitChanges() |
| 42 | + |
| 43 | +# ----------------------------------------------------------------------------- |
| 44 | +# Assert |
| 45 | +# ----------------------------------------------------------------------------- |
| 46 | +if ($manager.ApplicationPools["My Pool"] -eq $null -or $manager.ApplicationPools["sdij18uc"] -ne $null) { Write-Error "Our logic is wrong" } |
| 47 | +if ($manager.Sites["Website1"] -eq $null -or $manager.Sites["isjdjdsoidj"] -ne $null) { Write-Error "Our logic is wrong" } |
| 48 | +if ($manager.Sites["Website1"].Applications["/MyApp"] -eq $null -or $manager.Sites["Website1"].Applications["/sdidsuidshdsh"] -ne $null) { Write-Error "Our logic is wrong" } |
| 49 | + |
| 50 | +# ----------------------------------------------------------------------------- |
| 51 | +# Clean up |
| 52 | +# ----------------------------------------------------------------------------- |
| 53 | + |
| 54 | +. ..\_Teardown.IIS.ps1 |
| 55 | + |
| 56 | +Remove-IISSite -Name "Website1" -Confirm:$false |
| 57 | + |
| 58 | +$manager = Get-IISServerManager |
| 59 | +$manager.ApplicationPools["My Pool"].Delete() |
| 60 | +$manager.CommitChanges() |
0 commit comments