-
Notifications
You must be signed in to change notification settings - Fork 40
/
remove-storage-space.ps1
52 lines (47 loc) · 2.07 KB
/
remove-storage-space.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
#Variables names here MUST MATCH create-storage-space.ps1
$StoragePoolName = "My Storage Pool"
$SSDTierName = "SSDTier"
$HDDTierName = "HDDTier"
$TieredDiskName = "My Tiered VirtualDisk"
# Make sure they really want to do this!
$choices = '&Yes', '&No'
$decision = $Host.UI.PromptForChoice('Remove Storage Space', 'Are you sure you wish to remove the storage space named "' + $TieredDiskName + '"?' + [Environment]::NewLine + 'ALL DATA WILL BE PERMANENTLY LOST', $choices, 1)
if ($decision -ne 0) {
exit
}
# In reverse order of creation
if ((Get-VirtualDisk -FriendlyName $TieredDiskName) -ne $null){
Write-Output "Removing drive: $TieredDiskName"
Get-VirtualDisk -FriendlyName $TieredDiskName
Remove-virtualdisk -friendlyName $TieredDiskName -Confirm:$false
} else {
Write-Output "Drive does not exist: $TieredDiskName"
}
# Remove Storage Tier
if ((Get-StorageTier -FriendlyName $HDDTierName) -ne $null){
Write-Output "Removing storage tiers: $HDDTierName"
Get-StorageTier -FriendlyName $HDDTierName | FT FriendlyName, MediaType, Size -AutoSize
Remove-StorageTier -FriendlyName $HDDTierName -Confirm:$false
} else {
Write-Output "Tier does not exist: $HDDTierName"
}
if ((Get-StorageTier -FriendlyName $SSDTierName) -ne $null){
Write-Output "Removing storage tiers: $SSDTierName"
Get-StorageTier -FriendlyName $SSDTierName | FT FriendlyName, MediaType, Size -AutoSize
Remove-StorageTier -FriendlyName $SSDTierName -Confirm:$false
} else {
Write-Output "Tier does not exist: $SSDTierName"
}
Get-StorageTier
# Remove the Storage Pool
if ((Get-StoragePool -FriendlyName $StoragePoolName) -ne $null){
Write-Output "Removing storage pool: $StoragePoolName"
Get-StoragePool -FriendlyName $StoragePoolName | Get-PhysicalDisk | FT FriendlyName, MediaType
Remove-StoragePool -FriendlyName $StoragePoolName -Confirm:$false
} else {
Write-Output "Storage Pool does not exist: $StoragePoolName"
}
# Show just the primoridal pool
Write-Output "Poolable drives after cleanup"
Get-StoragePool | Get-PhysicalDisk -CanPool:$True
Write-Output "Operation complete"