This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Show-HierarchyVisualization.ps1
152 lines (142 loc) · 7.19 KB
/
Show-HierarchyVisualization.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
Clear-Host
$return = Read-Host -Prompt 'Enter the FQDN/IP to the Pure Storage FlashArray'
$user = Read-Host -Prompt 'Username'
$pwd = Read-Host -Prompt 'Password' -AsSecureString
$pattern = Read-Host -Prompt 'Enter Snapshot pattern to destroy and eradicate (Eg. VSS-)'
$timeframe = Read-Host -Prompt 'Enter Snapshot retention period in minutes (Eg. 2hr = 120)'
$FlashArray = New-PfaArray -EndPoint $return -Username $user -Password $pwd -IgnoreCertificateError
$Initiators = Get-PfaHosts -Array $FlashArray
$destroy = @()
Write-Host '============================'
Write-Host "Hosts on $return"
Write-Host '============================'
# Determine current FlashArray time.
$tempvol = [GUID]::NewGuid()
New-PfaVolume -Array $FlashArray -VolumeName $tempvol -Unit M -Size 1 | Out-Null
$array = Get-PfAvolume -Array $FlashArray -Name $tempvol
Remove-PfaVolumeOrSnapshot -Array $FlashArray -Name $tempvol | Out-Null
Remove-PfaVolumeOrSnapshot -Array $FlashArray -Name $tempvol -Eradicate | Out-Null
ForEach ($Initiator in $Initiators)
{
Write-Host " [H] $($Initiator.name)"
$Volumes = Get-PfaHostVolumeConnections -Array $FlashArray -Name $Initiator.name
If (!$Volumes)
{
Write-Host ' | |----[No volumes connected]'
}
Else
{
ForEach ($Volume in $Volumes)
{
Write-Host " | |----[V] $($Volume.vol)"
$Snapshots = Get-PfaVolumeSnapshots -Array $FlashArray -VolumeName $Volume.vol
ForEach ($Snapshot in $Snapshots)
{
If (($Snapshot.name) -like "*$pattern*")
{
# Based on US datetime format.
$TimeSpan = New-TimeSpan -Start ([datetime]$Snapshot.created) -End ([datetime]$array.created)
Write-Host "> | | |----[$pattern] $($Snapshot.name)"
If($TimeSpan.Minutes -ge $timeframe)
{
$destroy += $Snapshot.name
}
}
Else
{
Write-Host " | | |----[S] $($Snapshot.name)"
}
}
}
}
}
$voldestroylist = @($null)
ForEach ($vol in $destroy)
{
$voldestroylist += "$vol`r`n"
}
$destroy_retval = Read-Host -Prompt "`r`n`r`nDo you want to DESTROY $($voldestroylist.Count) snapshot(s) [Y/N]?"
If ($destroy_retval.ToUpper() -eq 'Y')
{
ForEach ($voldestroy_item in $voldestroylist)
{
#Only destroy volume. To add eradicate functionality add -Eradicate parameter.
#
#Uncomment below line for destroy to work.
#Remove-PfaVolumeOrSnapshot -Array $FlashArray -Name $voldestroy_item -ErrorAction SilentlyContinue | Out-Null
}
}
Disconnect-PfaArray -Array $FlashArray
# SIG # Begin signature block
# MIINIQYJKoZIhvcNAQcCoIINEjCCDQ4CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUX72+bnETEssSpFaALZPTWpl6
# nFOgggpjMIIFKzCCBBOgAwIBAgIQCamgNd9B0v6RJ4iA0KHDFDANBgkqhkiG9w0B
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz
# c3VyZWQgSUQg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