/
AZCleanup.psm1
661 lines (595 loc) · 26.4 KB
/
AZCleanup.psm1
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
Function AZConnect {
Add-AzAccount
}
Function ActivateDebug(){
Add-Content -Path $LogfileActivated -Value "***************************************************************************************************"
Add-Content -Path $LogfileActivated -Value "Started processing at [$([DateTime]::Now)]."
Add-Content -Path $LogfileActivated -Value "***************************************************************************************************"
Add-Content -Path $LogfileActivated -Value ""
Write-Host "Debug Enabled writing to logfile: " $LogfileActivated
}
Function WriteDebug{
[CmdletBinding()]
Param ([Parameter(Mandatory=$true)][string]$LineValue)
Process{
Add-Content -Path $LogfileActivated -Value $LineValue
}
}
Function GetSubscriptions{
#GETTING A LIST OF SUBSCRIPTIONS
Write-Host "Getting the subscriptions, please wait..."
$Subscriptions=Get-AzSubscription
Foreach ($subscription in $Subscriptions) {
$title = $subscription.name
$message = "Do you want this subscription to be added to the selection?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Adds the subscription to the script."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"Skips the subscription from scanning."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($result){
0 {
$selectedSubscriptions.Add($subscription) > $null
Write-host ($subscription.name + " has been added")
}
1 {Write-host ($subscription.name + " will be skipped")
}
}
}
return $selectedSubscriptions
}
Function Get-UnattachedNICs {
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter()]
$ResourceGroup
)
$context=Get-AzContext
If (!($context.Subscription.Id -eq $SubscriptionID)) {
Write-host "Switching Context"
Set-AzContext -Subscription $SubscriptionID
}
If ($ResourceGroup) {
$CollectionOfNICs=Get-AzNetworkInterface | where {($_.VirtualMachine -eq $null) -and $_.ResourceGroupName -eq $ResourceGroup }
}else{
#get all unattached disks
$CollectionOfNICs=Get-AzNetworkInterface | where {$_.VirtualMachine -eq $null }
}
#Check if there are any disks in the collection...
If (($CollectionOfNICs) -and ($CollectionOfNICs.count -gt 0)) {
return $CollectionOfNICs
}else{
return 0
}
}
Function ShowNICS{
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter()]
$ResourceGroup
)
If ($ResourceGroup) {
$nics=Get-UnattachedNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup
}else{
$nics=Get-UnattachedNICs $SubscriptionID
}
If (!($nics)){
Write-host "No nics found"
return $false
}else{
#Write-host "This lists shows all the nics and their number"
#Write-host "Please type the number of a NIC that needs a lock (or removed)"
#Write-host "or press C to continue with the deletion of all non-locked nics"
$i=0
Write-Host "[ Locked ]" -ForegroundColor Green
Write-host "[Unlocked]" -ForegroundColor Red
Foreach ($nic in $nics) {
#Check if the [0] in the array is the subscription if so, skip
If ($nic.Account) {
Write-host "CLEANING ARRAY"
$i=$i+1
next
}
#Check if there is a lock - and if so, add lock icon to the list of disks
$locked=ResourceLocked $nic
If ($locked) {
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Green
}else{
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Red
}
Write-host ($nic.name + " in resourceGroup " + $nic.ResourceGroupName )
$i=$i+1
}
return $nics
}
}
Function ShowResourceGroups {
Param (
[parameter(Mandatory)]
$SubscriptionID
)
$context=Get-AzContext
If (!($context.Subscription.Id -eq $SubscriptionID)) {
Write-host "Switching Context"
Set-AzContext -Subscription $SubscriptionID
}
$ResourceGroups=Get-AzResourceGroup
If (!($ResourceGroups)){
Write-host "No Resource Groups found"
return $false
}else{
#Write-host "This lists shows all the groups and their number"
#Write-host "Please type the number of the Resource Groups that needs a lock (or removed)"
$i=0
Write-Host "[ Locked ]" -ForegroundColor Green
Write-host "[Unlocked]" -ForegroundColor Red
Foreach ($group in $ResourceGroups) {
#Check if the [0] in the array is the subscription if so, skip
If ($group.Account) {
Write-host "CLEANING ARRAY"
$i=$i+1
next
}
#Check if there is a lock - and if so, add lock icon to the list of disks
$locked=ResourceLocked $group
If ($locked) {
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Green
}else{
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Red
}
Write-host ($group.name)
$i=$i+1
}
return $ResourceGroups
}
}
Function Get-UnattachedPIPs {
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter()]
$ResourceGroup
)
$context=Get-AzContext
If (!($context.Subscription.Id -eq $SubscriptionID)) {
Write-host "Switching Context"
Set-AzContext -Subscription $SubscriptionID
}
If ($ResourceGroup) {
$CollectionofPIPs=Get-AzPublicIpAddress | where {($_.IPConfiguration -eq $null) -and $_.ResourceGroupName -eq $ResourceGroup }
}else{
#get all unattached disks
$CollectionofPIPs=Get-AzPublicIpAddress | where {$_.IPConfiguration -eq $null}
}
#Check if there are any disks in the collection...
If (($CollectionofPIPs) -and ($CollectionofPIPs.count -gt 0)) {
return $CollectionofPIPs
}else{
return 0
}
}
Function ShowPIPs{
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter()]
$ResourceGroup
)
If ($ResourceGroup) {
$pips=Get-UnattachedPIPs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup
}else{
$pips=Get-UnattachedPIPs $SubscriptionID
}
If (!($pips)){
Write-host "No Public IP's found"
return $false
}else{
#Write-host "This lists shows all the Public IP's and their number"
#Write-host "Please type the number of a PIP that needs a lock (or removed)"
#Write-host "or press C to continue with the deletion of all non-locked PIP's"
$i=0
Write-Host "[ Locked ]" -ForegroundColor Green
Write-host "[Unlocked]" -ForegroundColor Red
Foreach ($pip in $pips) {
#Check if the [0] in the array is the subscription if so, skip
If ($pip.Account) {
Write-host "CLEANING ARRAY"
$i=$i+1
next
}
#Check if there is a lock - and if so, add lock icon to the list of disks
$locked=ResourceLocked $pip
If ($locked) {
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Green
}else{
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Red
}
Write-host ($pip.name + " in resourceGroup " + $pip.ResourceGroupName )
$i=$i+1
}
return $pips
}
}
Function ResourceLocked {
Param (
[parameter(Mandatory)]
$Resource,
[parameter()]
$ForResourceGroup
)
Write-Verbose ("CHECKING LOCK ON: " + $Resource.Name)
#Checks if a lock exists on a resource prior to deleting it
$ResourceType=($Resource.ID -split "/providers" | select -Last 1) -split ("/" + $Resource.Name) | select -first 1
If ($ForResourceGroup){
$Lock=Get-AzResourceLock -ResourceGroupName $Resource.Name | where {$_.ResourceType -eq 'Microsoft.Authorization/locks'}
}
else {
$Lock=Get-AzResourceLock -ResourceName $Resource.Name -ResourceGroupName $Resource.ResourceGroupName -ResourceType $ResourceType
}
If ($Lock.count -gt 1){
Write-Verbose ("FOUND MULTIPLE LOCKS: ")
ForEach ($lok in $lock){
Write-Verbose $lok
}
return $lock
}elseif ($lock){
Write-Verbose ("FOUND LOCK: " + $lock)
return $lock
}else{
Write-Verbose "No Lock Found"
return $false
}
}
Function ApplyResourceLock {
Param (
[parameter(Mandatory)]
$Resource,
[parameter()]
$ForResourceGroup
)
Write-Verbose ("inbound object to lock: " + $Resource.Name)
#This Function is used to set a lock on a resource. Validate the lock exist and return the lock name.
$Account=(Get-AzContext).Account.id
$ResourceType=($Resource.ID -split "/providers" | select -Last 1) -split ("/" + $Resource.Name) | select -first 1
If ($ForResourceGroup) {
Set-AzResourceLock -LockLevel CanNotDelete -LockName "NoDelete" -LockNotes ("added by cleanup script: " + $Account) -ResourceGroupName $Resource.ResourceGroupName -Force
$Lock=Get-AzResourceLock -ResourceGroupName $Resource.Name | where {$_.ResourceType -eq 'Microsoft.Authorization/locks'}
}else {
Set-AzResourceLock -LockLevel CanNotDelete -LockName "NoDelete" -LockNotes ("added by cleanup script: " + $Account) -ResourceName $Resource.Name -ResourceType $ResourceType -ResourceGroupName $Resource.ResourceGroupName -Force
$Lock=Get-AzResourceLock -ResourceName $Resource.Name -ResourceGroupName $Resource.ResourceGroupName -ResourceType $ResourceType
}
}
Function RemoveResourceLock {
Param (
[parameter(Mandatory)]
$Resource,
[parameter()]
$ForResourceGroup
)
Write-Verbose ("inbound object to unlock: " + $Resource.Name)
#This Function is used to remove lock from a resource. Validate the lock exist and return the lock name.
#first we need to check if there is a lock, secondly if that lock is on the object or higher level
$ResourceType=($Resource.ID -split "/providers" | select -Last 1) -split ("/" + $Resource.Name) | select -first 1
$Lock=Get-AzResourceLock -ResourceName $Resource.Name -ResourceGroupName $Resource.ResourceGroupName -ResourceType $ResourceType
#Write-Verbose $Lock
If ($Lock.count -gt 1) {
write-host "parent lock or multiple locks found, cannot remove single lock" -ForegroundColor Red
Foreach ($loc in $lock) {
write-host $lock.ResourceType
}
}elseif($Lock){
#VALIDATE IF THE LOCK IS REMOVABLE - ON THE OBJECT ITSELF
Write-verbose " in deletion block"
If (("/" + $Lock.ResourceType) -eq $ResourceType ) {
#WE CAN REMOVE IT
Write-Verbose ("Removing lock:" + $Lock.LockID)
Remove-AzResourceLock -LockId $Lock.LockId -Force
}Else{
Write-Host "Parent lock detected, cannot remove" -ForegroundColor Red
Write-Verbose ("Lock found: " + $Lock.ResourceType)
Write-Verbose ("Resource : " + $ResourceType)
}
}else{
Write-host "No lock found"
}
}
Function Get-UnattachedDisks{
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter()]
$ResourceGroup
)
$context=Get-AzContext
If (!($context.Subscription.Id -eq $SubscriptionID)) {
Write-host "Switching Context"
Set-AzContext -Subscription $SubscriptionID
}
If ($ResourceGroup) {
#Write-host "Retrieving all disks in Resource Group: $ResourceGroup"
$CollectionOfDisks=get-azdisk | where {($_.DiskState -eq 'Unattached') -and ($_.ResourceGroupName -eq $ResourceGroup)}
}else{
#get all unattached disks
#Write-host "Retrieving all disks"
$CollectionOfDisks=get-azdisk | where {$_.DiskState -eq 'Unattached'}
}
#Check if there are any disks in the collection...
If (($CollectionOfDisks) -and ($CollectionOfDisks.count -gt 0)) {
return $CollectionOfDisks
}else{
#write-host ":: Returning 0 disks"
return $false
}
}
Function ShowDisks{
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter()]
$ResourceGroup
)
If ($ResourceGroup) {
$disks=Get-UnattachedDisks -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup
}else{
$disks=Get-UnattachedDisks $SubscriptionID
}
If (!($disks)){
Write-host "No disks found"
return $false
}else{
#Write-host "This lists shows all the disks and their number"
#Write-host "Please type the number of a disk that needs a lock (or removed)"
#Write-host "or press C to continue with the deletion of all non-locked disks"
$i=0
Write-Host "[ Locked ]" -ForegroundColor Green
Write-host "[Unlocked]" -ForegroundColor Red
Foreach ($disk in $disks) {
#Check if the [0] in the array is the subscription if so, skip
If ($disk.Account) {
#Write-host "CLEANING ARRAY"
$i=$i+1
next
}
#Check if there is a lock - and if so, add lock icon to the list of disks
$locked=ResourceLocked $disk
If ($locked) {
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Green
}else{
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Red
}
Write-host ($disk.name + " in resourceGroup " + $disk.ResourceGroupName )
$i=$i+1
}
return $disks
}
}
Function DeleteObject{
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter(Mandatory)]
$ObjectType,
[parameter()]
$ResourceGroup,
[parameter()]
$Confirmed
)
If (!($ResourceGroup)){
Write-Verbose ("No Resource group specified" )
Switch ($ObjectType) {
"Disks" {[array]$objects=Get-UnattachedDisks $SubscriptionID}
"NICs" {[array]$objects=Get-UnattachedNICs $SubscriptionID}
"PIPs" {[array]$objects=Get-UnattachedNICs $SubscriptionID}
}
}else{
Write-Verbose ("Resource group limitation: " + $ResourceGroup )
Switch ($ObjectType) {
"Disks" {[array]$objects=Get-UnattachedDisks -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"NICs" {[array]$objects=Get-UnattachedNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"PIPs" {[array]$objects=Get-UnattachedNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
}
}
If ($objects){
Foreach ($object in $objects) {
#Check if the [0] in the array is the subscription if so, skip
If ($object.Account) {
#Write-host "CLEANING ARRAY"
$i=$i+1
next
}
#Check if there is a lock - and if so, add lock icon to the list of disks
$locked=ResourceLocked $object
If ($locked) {
Write-verbose ($object.name + " locked")
}else{
Write-Verbose ("deleting: " + $object.name)
If ($Confirmed) {
Write-host ("Deleting " + $Object.Name + " in Resource Group: " + $object.ResourceGroupName)
Switch ($ObjectType){
"Disks" {get-azdisk -ResourceGroupName $object.ResourceGroupName -DiskName $object.Name | Remove-AzDisk -Force}
"NICs" {Get-AzNetworkInterface -ResourceID $object.id | Remove-AzNetworkInterface -Force}
"PIPs" {Get-AzPublicIpAddress -ResourceGroupName $object.ResourceGroupName -Name $object.Name | Remove-AzPublicIpAddress -Force}
}
}else{
Switch ($ObjectType){
"Disks" {get-azdisk -ResourceGroupName $object.ResourceGroupName -DiskName $object.Name | Remove-AzDisk -WhatIf}
"NICs" {Get-AzNetworkInterface -ResourceID $object.id | Remove-AzNetworkInterface -WhatIf}
"PIPs" {Get-AzPublicIpAddress -ResourceGroupName $object.ResourceGroupName -Name $object.Name | Remove-AzPublicIpAddress -WhatIf}
}
}
}
}
}
}
Function SelectScope{
Param (
[parameter(Mandatory)]
$SubscriptionID
)
$ResourceGroups=Get-AzResourceGroup
If ($ResourceGroups) {
$i=0
Foreach ($ResourceGroup in $ResourceGroups) {
#Check if the [0] in the array is the subscription if so, skip
If ($ResourceGroup.Account) {
$i=$i+1
next
}
Write-host ("[" + $i + "] ") -NoNewline -ForegroundColor Green
Write-host $ResourceGroup.ResourceGroupName
$i=$i+1
}
$SelectedObject = Read-Host -Prompt 'Type the number to set the scope to that resource group'
If ( $SelectedObject -match '\d' ) {
$RS=$ResourceGroups[$SelectedObject]
Write-Host ("Selected ResourceGroup: " + $ResourceGroups[$SelectedObject].ResourceGroupName)
return $RS.ResourceGroupName
}else{
Write-host "not a number - NO RESOURCE GROUP SELECTED"
return $false
}
#number selected is #SelectedObject
}else{
Write-host "no resource groups found"
return $false
}
}
Function SelectOperationsTarget{
Param (
[parameter(Mandatory)]
$SubscriptionID,
[parameter()]
$Confirmed,
[parameter()]
$ResourceGroup
)
#SET Confirmed to false if not specified.. will not delete by default
If (!($Confirmed)) {$Confirmed = $false}
#Select disks, NICs or IP's
Do {
write-host ("using subscription: " + $SubscriptionID)
write-host "Which resource type should be targgetted"
$SelectedObjectType = Read-Host -Prompt 'D[DISK], N[NICs], P[Public IP], R[Resource Groups], S[SCOPE], Q[QUIT]'
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks $SubscriptionID}
"N" {$Resource=ShowNICs $SubscriptionID}
"P" {$Resource=ShowPIPs $SubscriptionID}
"R" {$ResourceGroup=ShowResourceGroups $SubscriptionID}
"S" {
$ResourceGroup=SelectScope -SubscriptionID $SubscriptionID
$SelectedObjectType = Read-Host -Prompt 'D[DISK], N[NICs], P[Public IP], R[Resource Groups], Q[QUIT]'
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"N" {$Resource=ShowNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"P" {$Resource=ShowPIPs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"R" {$Resource=ShowResourceGroups -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
}
}
"Q" {break}
}
$break=$false
DO {
$SelectedObject = Read-Host -Prompt 'Type the number to be selected, R [Refresh], D [DELETE], S [SELECT], or Q [QUIT]'
If (($SelectedObject.ToLower() -ne "q" -or $SelectedObject.ToLower() -eq 'r' -or $SelectedObject.ToLower() -eq 'd') -and $SelectedObject -match '\d' ) {
#number selected is #SelectedObject
$ObjectAction = Read-Host -Prompt 'type L (LOCK), U (UNLOCK), R [REFRESH], or C [CONTINUE}'
Switch ($ObjectAction.ToUpper()){
"L" {
Write-host ("Applying lock to:" + $Resource[$SelectedObject].Name + " in resource group: " + $Resource[$SelectedObject].ResourceGroupName)
Write-Verbose ("Running operation on: " + $Resource[$SelectedObject])
$Lock=ApplyResourceLock ($Resource[$SelectedObject])
If (!($ResourceGroup)){
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks $SubscriptionID}
"N" {$Resource=ShowNICs $SubscriptionID}
"I" {$Resource=ShowPIPs $SubscriptionID}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}else{
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"N" {$Resource=ShowNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"I" {$Resource=ShowPIPs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}
}
"U"{
Write-host ("Trying to remove lock from: " + $Resource[$SelectedObject].Name + " in resource group: " + $Resource[$SelectedObject].ResourceGroupName)
Write-Verbose ("Running operation on: " + $Resource[$SelectedObject])
$Lock=RemoveResourceLock ($Resource[$SelectedObject])
If (!($ResourceGroup)){
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks $SubscriptionID}
"N" {$Resource=ShowNICs $SubscriptionID}
"I" {$Resource=ShowPIPs $SubscriptionID}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}else{
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"N" {$Resource=ShowNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"I" {$Resource=ShowPIPs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}
}
"R"{
If (!($ResourceGroup)){
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks $SubscriptionID}
"N" {$Resource=ShowNICs $SubscriptionID}
"I" {$Resource=ShowPIPs $SubscriptionID}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}else{
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"N" {$Resource=ShowNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"I" {$Resource=ShowPIPs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}
}
"C"{
Write-host "continue"
break
}
}
}elseif ($SelectedObject.ToLower() -eq "s") {
#QUIT
break
}elseif ($SelectedObject.ToLower() -eq "r"){
#need to refresh
If (!($ResourceGroup)){
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks $SubscriptionID}
"N" {$Resource=ShowNICs $SubscriptionID}
"I" {$Resource=ShowPIPs $SubscriptionID}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}else{
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=ShowDisks -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"N" {$Resource=ShowNICs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"I" {$Resource=ShowPIPs -SubscriptionID $SubscriptionID -ResourceGroup $ResourceGroup}
"R" {$Resource=ShowResourceGroups $SubscriptionID}
}
}
}elseif ($SelectedObject.ToLower() -eq "d") {
Write-host "RUN DELETE SEQUENCE"
#RUN DELETE SEQUENCE
Switch ($SelectedObjectType.ToUpper()) {
"D" {$Resource=DeleteObject -SubscriptionID $SubscriptionID -ObjectType "Disks" -Confirmed $Confirmed}
"N" {$Resource=DeleteObject -SubscriptionID $SubscriptionID -ObjectType "NICs" -Confirmed $Confirmed}
"I" {$Resource=DeleteObject -SubscriptionID $SubscriptionID -ObjectType "PIPs" -Confirmed $Confirmed}
}
}elseif ($SelectedObject.ToLower() -eq "q") {
$break=$true
}
}while ($break -ne $true)
}while ($mainloop -ne $true)
}