-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-website-in-IIS.ps1
84 lines (72 loc) · 2.44 KB
/
create-website-in-IIS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function LogDebug($message) {
Write-Host -ForegroundColor DarkGray $message
}
function LogInformation($message) {
Write-Host -ForegroundColor Cyan $message
}
function LogSuccess($message) {
Write-Host -ForegroundColor Green $message
}
function LogWarning($message) {
Write-Host -ForegroundColor Yellow $message
}
function LogError($message) {
Write-Host -ForegroundColor Red $message
}
function ExitFromScript($message,$line,$details) {
$message = $_.Exception.Message
$line = $_.InvocationInfo.ScriptLineNumber
$details = $_.CategoryInfo
LogError "An Error has occurred: $message
`nline: $line
`nError Details: $details"
LogWarning "Stopping the script.`n"
LogWarning "Press any key...`n"
$null = Read-Host
Exit
}
################# First usage #################
function CreateWebsite($Site,$Port,$Path) {
LogInformation "- Creating website $websiteName ..."
LogDebug " Creating website $websiteName ..."
if (-not (Get-Website -Name "$websiteName" -ErrorAction SilentlyContinue)) {
New-Website -Name "$websiteName" -PhysicalPath "$Path" -Port $Port #####
Start-Website -Name "$websiteName" # check is started
LogSuccess " Create website $websiteName successfully!`n"
}
else {
LogWarning " website already exists.`n"
}
}
param(
[Parameter(Position = 0, mandatory)]
[string]$Site,
[Parameter(Position = 1, mandatory)]
[string]$Port,
[Parameter(Position = 2, mandatory)]
[string]$Path
)
CreateWebsite $Site $Port $Path
################# second usage #################
function CreateWebsite($arrOfSitesInfo) {
$websiteName = $arrOfSitesInfo["Site"]
$Port = $arrOfSitesInfo["Port"]
$physicalPath = $arrOfSitesInfo["Path"]
LogInformation "- Creating website $websiteName ..."
LogDebug " Creating website $websiteName ..."
if (-not (Get-Website -Name "$websiteName" -ErrorAction SilentlyContinue)) {
New-Website -Name "$websiteName" -PhysicalPath "$physicalPath" -Port $Port #####
Start-Website -Name "$websiteName" # check is started
LogSuccess " Create website $websiteName successfully!`n"
}
else {
LogWarning " website already exists.`n"
}
}
$WebSite_Details = @(
@{Site = "Public" ; Port = 80 ; Path = "path\root2"},
@{Site = "Private"; Port = 8080; Path = "path\root" }
)
foreach ($args in $WebSite_Details) {
CreateWebsite $args
}