forked from daveolker/Populate-HPE-Synergy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cleanup_HPE_Synergy.ps1
315 lines (249 loc) · 10.2 KB
/
Cleanup_HPE_Synergy.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
##############################################################################
# Cleanup_HPE_Syergy.ps1
#
# - Example script for de-configuring the HPE Synergy Appliance
#
# VERSION 5.40
#
# AUTHORS
# Dave Olker - HPE Storage and Big Data
#
# (C) Copyright 2020 Hewlett Packard Enterprise Development LP
##############################################################################
<#
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
#>
# ------------------ Parameters
Param ( [String]$OVApplianceIP = "192.168.62.128",
[String]$OVAdminName = "Administrator",
[String]$OVAuthDomain = "Local",
[String]$OneViewModule = "HPEOneView.540"
)
function Get-TimeStamp {
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}
function Remove_Logical_Enclosures
{
Write-Host "$(Get-TimeStamp) Removing all Logical Enclosures"
Get-OVLogicalEnclosure | Remove-OVLogicalEnclosure -Force -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Logical Enclosures Removed"
}
function Remove_Enclosure_Groups
{
Write-Host "$(Get-TimeStamp) Removing all Enclosure Groups"
Get-OVEnclosureGroup | Remove-OVEnclosureGroup -Force -Confirm:$false
Write-Host "$(Get-TimeStamp) All Enclosure Groups Removed"
}
function Remove_Logical_Interconnect_Groups
{
Write-Host "$(Get-TimeStamp) Removing all Logical Interconnect Groups"
Get-OVLogicalInterconnectGroup | Remove-OVLogicalInterconnectGroup -Force -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Logical Interconnect Groups Removed"
}
function Remove_OS_Deployment_Servers
{
Write-Host "$(Get-TimeStamp) Removing all OS Deployment Servers"
Get-OVOSDeploymentServer | Remove-OVOSDeploymentServer -Confirm:$false | Wait-OVTaskComplete
#
# Sleep for 400 seconds to allow the OS Deployment Cluster to Form
#
#Sleep -Seconds 400
Write-Host "$(Get-TimeStamp) All OS Deployment Servers Removed"
}
function Remove_Server_Profile_Templates
{
Write-Host "$(Get-TimeStamp) Removing all Server Profile Templates"
Get-OVServerProfileTemplate | Remove-OVServerProfileTemplate -Force -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Server Profile Templates Removed"
}
function Remove_Server_Profiles
{
Write-Host "$(Get-TimeStamp) Removing all Server Profiles"
Get-OVServerProfile | Remove-OVserverProfile -Force -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Server Profiles Removed"
}
function Rename_Enclosures
{
Write-Host "$(Get-TimeStamp) Renaming Enclosures"
$Enc = Get-OVEnclosure -Name Synergy-Encl-1 -ErrorAction SilentlyContinue
Set-OVEnclosure -Name "0000A66101" -Enclosure $Enc | Wait-OVTaskComplete
$Enc = Get-OVEnclosure -Name Synergy-Encl-2 -ErrorAction SilentlyContinue
Set-OVEnclosure -Name "0000A66102" -Enclosure $Enc | Wait-OVTaskComplete
$Enc = Get-OVEnclosure -Name Synergy-Encl-3 -ErrorAction SilentlyContinue
Set-OVEnclosure -Name "0000A66103" -Enclosure $Enc | Wait-OVTaskComplete
$Enc = Get-OVEnclosure -Name Synergy-Encl-4 -ErrorAction SilentlyContinue
Set-OVEnclosure -Name "0000A66104" -Enclosure $Enc | Wait-OVTaskComplete
$Enc = Get-OVEnclosure -Name Synergy-Encl-5 -ErrorAction SilentlyContinue
Set-OVEnclosure -Name "0000A66105" -Enclosure $Enc | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Enclosures Renamed"
}
function Remove_Storage_Volume_Templates
{
Write-Host "$(Get-TimeStamp) Removing all Storage Volume Templates"
Get-OVStorageVolumeTemplate | Remove-OVStorageVolumeTemplate -Force -Confirm:$false
Write-Host "$(Get-TimeStamp) All Storage Volume Templates Removed"
}
function Remove_Storage_Volumes
{
Write-Host "$(Get-TimeStamp) Removing all Storage Volumes"
Get-OVStorageVolume | Remove-OVStorageVolume -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Storage Volumes Removed"
}
function Remove_Storage_Pools
{
Write-Host "$(Get-TimeStamp) Removing all Storage Pools"
Get-OVStoragePool | Remove-OVStoragePool -Force -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Storage Pools Removed"
}
function Remove_Storage_Systems
{
Write-Host "$(Get-TimeStamp) Removing all Storage Systems"
Get-OVStorageSystem | Remove-OVStorageSystem -Force -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Storage Systems Removed"
}
function Remove_Network_Sets
{
Write-Host "$(Get-TimeStamp) Removing all Network Sets"
Get-OVNetworkSet | Remove-OVNetworkSet -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Network Sets Removed"
}
function Remove_Networks
{
Write-Host "$(Get-TimeStamp) Removing all Networks"
Get-OVNetwork | Remove-OVNetwork -Force -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Networks Removed"
}
function Remove_IPv4_Address_Pool_Ranges
{
Write-Host "$(Get-TimeStamp) Removing all IPv4 Address Pool Ranges"
Get-OVAddressPoolRange | Remove-OVAddressPoolRange -Confirm:$false
Write-Host "$(Get-TimeStamp) All IPv4 Address Pools Removed"
}
function Remove_IPv4_Subnets
{
Write-Host "$(Get-TimeStamp) Removing all IPv4 Subnets"
Get-OVAddressPoolSubnet | Remove-OVAddressPoolSubnet -Confirm:$false
Write-Host "$(Get-TimeStamp) All IPv4 Subnets Removed"
}
function Remove_SAN_Managers
{
Write-Host "$(Get-TimeStamp) Removing all SAN Managers"
Get-OVSanManager | Remove-OVSanManager -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All SAN Managers Removed"
}
function Remove_Licenses
{
Write-Host "$(Get-TimeStamp) Removing all Licenses"
Get-OVLicense | Remove-OVLicense -Confirm:$false
Write-Host "$(Get-TimeStamp) All Licenses Removed"
}
function Remove_Firmware_Bundles
{
Write-Host "$(Get-TimeStamp) Removing all Fimrware Bundles"
Get-OVBaseline | Remove-OVBaseline -Confirm:$false | Wait-OVTaskComplete
Write-Host "$(Get-TimeStamp) All Firmware Bundles Removed"
}
function Remove_New_Users
{
Write-Host "$(Get-TimeStamp) Removing all non-default Users"
Get-OVUser -Name BackupAdmin | Remove-OVUser -Confirm:$false
Get-OVUser -Name NetworkAdmin | Remove-OVUser -Confirm:$false
Get-OVUser -Name ServerAdmin | Remove-OVUser -Confirm:$false
Get-OVUser -Name StorageAdmin | Remove-OVUser -Confirm:$false
Get-OVUser -Name SoftwareAdmin | Remove-OVUser -Confirm:$false
Write-Host "$(Get-TimeStamp) All non-default Users Removed"
}
function Remove_Scopes
{
Write-Host "$(Get-TimeStamp) Removing all Scopes"
Get-OVScope -Name FinanceScope | Remove-OVScope -Confirm:$false
Write-Host "$(Get-TimeStamp) All Scopes Removed"
}
##############################################################################
#
# Main Program
#
##############################################################################
#
# Unload any earlier versions of the HPOneView POSH modules
#
Remove-Module -ErrorAction SilentlyContinue HPOneView.120
Remove-Module -ErrorAction SilentlyContinue HPOneView.200
Remove-Module -ErrorAction SilentlyContinue HPOneView.300
Remove-Module -ErrorAction SilentlyContinue HPOneView.310
Remove-Module -ErrorAction SilentlyContinue HPOneView.400
Remove-Module -ErrorAction SilentlyContinue HPOneView.410
Remove-Module -ErrorAction SilentlyContinue HPOneView.420
Remove-Module -ErrorAction SilentlyContinue HPOneView.500
Remove-Module -ErrorAction SilentlyContinue HPOneView.520
Remove-Module -ErrorAction SilentlyContinue HPEOneView.530
if (-not (Get-Module HPEOneview.540))
{
Import-Module -Name HPEOneView.540
}
if (-not $ConnectedSessions)
{
$ApplianceIP = Read-Host -Prompt "Synergy Composer IP Address [$OVApplianceIP]"
if ([string]::IsNullOrWhiteSpace($ApplianceIP))
{
$ApplianceIP = $OVApplianceIP
}
$AdminName = Read-Host -Prompt "Administrator Username [$OVAdminName]"
if ([string]::IsNullOrWhiteSpace($AdminName))
{
$AdminName = $OVAdminName
}
$AdminCred = Get-Credential -UserName $AdminName -Message "Password required for the user '$AdminName'"
if ([string]::IsNullOrWhiteSpace($AdminCred))
{
Write-Host "$(Get-TimeStamp) Blank Credential is not permitted. Exiting."
Exit
}
Connect-OVMgmt -Hostname $ApplianceIP -Credential $AdminCred -AuthLoginDomain $OVAuthDomain -ErrorAction Stop
if (-not $ConnectedSessions)
{
Write-Host "$(Get-TimeStamp) Login to Synergy System failed. Exiting."
Exit
}
}
Write-Host "$(Get-TimeStamp) De-Configuring HPE Synergy Appliance"
Remove_Server_Profiles
Remove_Server_Profile_Templates
Remove_Logical_Enclosures
Remove_Enclosure_Groups
Remove_Logical_Interconnect_Groups
Rename_Enclosures
Remove_Storage_Volume_Templates
Remove_Storage_Volumes
Remove_Storage_Pools
Remove_Storage_Systems
#
# Disabled the removal of OS Deployment Server since
# it causes the OS Deployment appliance to stop working
#
#Remove_OS_Deployment_Servers
Remove_Network_Sets
Remove_Networks
Remove_IPv4_Address_Pool_Ranges
Remove_IPv4_Subnets
Remove_SAN_Managers
Remove_Licenses
Remove_New_Users
Remove_Scopes
Remove_Firmware_Bundles
Write-Host "$(Get-TimeStamp) HPE Synergy Appliance De-configuration Complete"
Disconnect-OVMgmt