|
@@ -0,0 +1,155 @@
|
|
1
|
+$basedir = "C:\inetpub\"
|
|
2
|
+$baseweb = "IIS:\Sites\"
|
|
3
|
+$basepool = "IIS:\AppPools\"
|
|
4
|
+$sqlinstance = "."
|
|
5
|
+
|
|
6
|
+$Shares=[WMICLASS]”WIN32_Share”
|
|
7
|
+Import-Module WebAdministration
|
|
8
|
+[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
|
|
9
|
+$sqlserver = New-Object Microsoft.SqlServer.Management.Smo.Server($sqlinstance)
|
|
10
|
+
|
|
11
|
+function sitegen($name)
|
|
12
|
+{
|
|
13
|
+ $sitedir = "$basedir$name"
|
|
14
|
+ $siteweb = "$baseweb$name"
|
|
15
|
+ $sitepool = "$basepool$name"
|
|
16
|
+
|
|
17
|
+ if (siteexists($name))
|
|
18
|
+ {
|
|
19
|
+ return $false
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+ # Create app pool
|
|
23
|
+ New-Item $sitepool | out-null
|
|
24
|
+
|
|
25
|
+ # Create website
|
|
26
|
+ New-Item $siteweb -bindings @{protocol="http";bindingInformation=":80:$name"} -physicalPath $sitedir | out-null
|
|
27
|
+ Set-ItemProperty $siteweb -name applicationPool -value $name | out-null
|
|
28
|
+
|
|
29
|
+ # Create directory
|
|
30
|
+ New-Item $sitedir -type directory | out-null
|
|
31
|
+
|
|
32
|
+ # Create share
|
|
33
|
+ $Shares.Create($sitedir, $name, 0) | out-null
|
|
34
|
+
|
|
35
|
+ return $true
|
|
36
|
+}
|
|
37
|
+
|
|
38
|
+function siteexists($name)
|
|
39
|
+{
|
|
40
|
+ $sitedir = "$basedir$name"
|
|
41
|
+ $siteweb = "$baseweb$name"
|
|
42
|
+ $sitepool = "$basepool$name"
|
|
43
|
+ return (Test-path($sitedir)) -or (Test-path($sitedir)) -or (Test-path($sitepool))
|
|
44
|
+}
|
|
45
|
+
|
|
46
|
+function siterm($name)
|
|
47
|
+{
|
|
48
|
+ $sitedir = "$basedir$name"
|
|
49
|
+ $siteweb = "$baseweb$name"
|
|
50
|
+ $sitepool = "$basepool$name"
|
|
51
|
+
|
|
52
|
+ # Remove directory
|
|
53
|
+ if (Test-Path $sitedir)
|
|
54
|
+ {
|
|
55
|
+ Remove-Item $sitedir -Recurse | out-null
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ # Remove website
|
|
59
|
+ if (Test-Path $siteweb)
|
|
60
|
+ {
|
|
61
|
+ Remove-Item $siteweb -Recurse | out-null
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ # Remove app pool
|
|
65
|
+ if (Test-Path $sitepool)
|
|
66
|
+ {
|
|
67
|
+ Remove-Item $sitepool -Recurse | out-null
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ # Remove share
|
|
71
|
+ $share = Get-WmiObject -Class Win32_Share -ComputerName . -Filter "Name='$name'"
|
|
72
|
+ if ($share)
|
|
73
|
+ {
|
|
74
|
+ $share.delete() | out-null
|
|
75
|
+ }
|
|
76
|
+}
|
|
77
|
+
|
|
78
|
+function dbgen($name)
|
|
79
|
+{
|
|
80
|
+ if (dbexists($name))
|
|
81
|
+ {
|
|
82
|
+ return $false
|
|
83
|
+ }
|
|
84
|
+ $db = New-Object Microsoft.SqlServer.Management.Smo.Database($sqlserver, $name)
|
|
85
|
+ $db.Create() | out-null
|
|
86
|
+ return $true
|
|
87
|
+}
|
|
88
|
+
|
|
89
|
+function dbexists($name)
|
|
90
|
+{
|
|
91
|
+ $db = $sqlserver.Databases[$name]
|
|
92
|
+ if ($db)
|
|
93
|
+ {
|
|
94
|
+ return $true
|
|
95
|
+ }
|
|
96
|
+ else
|
|
97
|
+ {
|
|
98
|
+ return $false
|
|
99
|
+ }
|
|
100
|
+}
|
|
101
|
+
|
|
102
|
+function dbrm($name)
|
|
103
|
+{
|
|
104
|
+ if (dbexists($name))
|
|
105
|
+ {
|
|
106
|
+ $sqlserver.KillDatabase($name) | out-null
|
|
107
|
+ }
|
|
108
|
+}
|
|
109
|
+
|
|
110
|
+function apigen($name)
|
|
111
|
+{
|
|
112
|
+ return (sitegen("api.$name")) -and (dbgen($name))
|
|
113
|
+}
|
|
114
|
+
|
|
115
|
+function apiexists($name)
|
|
116
|
+{
|
|
117
|
+ return (siteexists("api.$name")) -or (dbexists($name))
|
|
118
|
+}
|
|
119
|
+
|
|
120
|
+function apirm($name)
|
|
121
|
+{
|
|
122
|
+ siterm("api.$name")
|
|
123
|
+ dbrm($name)
|
|
124
|
+}
|
|
125
|
+
|
|
126
|
+function frontgen($name)
|
|
127
|
+{
|
|
128
|
+ return (sitegen($name))
|
|
129
|
+}
|
|
130
|
+
|
|
131
|
+function frontexists($name)
|
|
132
|
+{
|
|
133
|
+ return (siteexists($name))
|
|
134
|
+}
|
|
135
|
+
|
|
136
|
+function frontrm($name)
|
|
137
|
+{
|
|
138
|
+ siterm($name)
|
|
139
|
+}
|
|
140
|
+
|
|
141
|
+function appgen($name)
|
|
142
|
+{
|
|
143
|
+ return (frontgen($name)) -and (apigen($name))
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+function appexists($name)
|
|
147
|
+{
|
|
148
|
+ return (frontexists($name)) -or (apiexists($name))
|
|
149
|
+}
|
|
150
|
+
|
|
151
|
+function apprm($name)
|
|
152
|
+{
|
|
153
|
+ frontrm($name)
|
|
154
|
+ apirm($name)
|
|
155
|
+}
|