-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvsan_XML.ps1
121 lines (102 loc) · 4.64 KB
/
vsan_XML.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
# A PowerCLI script that retrieves VSAN info in XML format.
# Jason Fenech (Aug 16)
#----------------------------------------------------------[Libraries]-----------------------------------------------
# Uncomment the 2 lines below if running script using PowerShell (not PowerCLI)
#
# Import-Module VMware.VimAutomation.Core -ErrorAction:SilentlyContinue
# Import-Module VMware.VimAutomation.Storage -ErrorAction:SilentlyContinue
#----------------------------------------------------------[Declarations]--------------------------------------------
#Change the following as required
####################################################################################
$vSANFile = "C:\test\vsan.xml" #Path to report
$vCenter="vcenter60qa.local" #vCenter hostname or IP Address
$clusName = "VSAN" #Cluster name
$user="xxxxxxx" #vCenter Server user
$pass="xxxxxxx" #vCenter Server user's password
$vSANPolName="Virtual SAN Default Storage Policy" #vSAN Storage Poicy
$vSANDSName="vsanDatastore" #Default name for the VSAN DS
####################################################################################
$vSANIssues="" #String var holding VSAN error / warning msg
$dn=0 #Used a disk counter
#----------------------------------------------------------[Execution]-----------------------------------------------
#Drop any existing open VI connections and connect to vCenter Server $vCenter
try{
Disconnect-VIServer -Confirm:$false -ErrorAction:SilentlyContinue
Connect-VIServer -Server $vCenter -User $user -Password $pass -ErrorAction:Stop
}
catch{
Write-Host "Failed to connect to vCenter Server $vCenter"
exit #Exit script on error
}
#Retrieve cluster and vSAN info
$Clus = Get-Cluster -Name $clusName
$vSanDisks = Get-VSanDisk
$vSanDGroups = Get-VsanDiskGroup
$vSANPolicy = (Get-SpbmStoragePolicy -Name $vSANPolName).AnyOfRuleSets.allofrules
$vSANDS = (Get-Datastore -Name $vSANDSName)
#Write vSAN info to file $vSANFile
#vSAN Settings
(@"
<?xml version="1.0"?>
<VSAN>
<General_Info>
<Is_VSAN_Enabled>$($clus.VsanEnabled)</Is_VSAN_Enabled>
<No_Of_Disk_Groups>$(($vSanDGroups).count)</No_Of_Disk_Groups>
<No_of_SSD_Disks>$(($vSanDisks | where {$_.IsSSD -eq "True"}).count)</No_of_SSD_Disks>
<No_of_Non_SSD_Disks>$(($vSanDisks | where {$_.IsSSD -ne "True"}).count)</No_of_Non_SSD_Disks>
<Disk_Claim_Mode>$($clus.VsanDiskClaimMode)</Disk_Claim_Mode>
</General_Info>
"@) | Out-File $vSANFile -Append
#-------------------------------------------------------------------------------------
#vSAN Health Info
if ( $Clus.ExtensionData.ConfigIssue.ObjectName -eq "VSAN") {$vSANIssues = $Clus.ExtensionData.ConfigIssue[0].FullFormattedMessage}
(@"
<Health>
<Issues>$vSANIssues</Issues>
</Health>
<Disks>
"@) | Out-File $vSANFile -Append
#-------------------------------------------------------------------------------------
#vSAN Disks Info
$vSanDisks | % {
(@"
<Disk_$dn>
<Number>$dn</Number>
<Name>$($_.Name)</Name>
<Health>$($_.ExtensionData.OperationalState)</Health>
<Vendor>$($_.ExtensionData.Vendor)</Vendor>
<Model>$($_.ExtensionData.Model)</Model>
<SSD>$($_.IsSsd)</SSD>
<Size_GB>$(($_.ExtensionData.Capacity.BlockSize * $_.ExtensionData.Capacity.Block) / (1024*1024*1024)))</Size_GB>
<Queue_Length>$($_.ExtensionData.QueueDepth)</Queue_Length>
<Format_Ver>$($_.ExtensionData.VsanDiskInfo.FormatVersion)</Format_Ver>
<vSAN_UIID>$($_.ExtensionData.VsanDiskInfo.VsanUuid)</vSAN_UIID>
<ESXi_Host>$($_.VsanDiskGroup.vmhost.name)</ESXi_Host>
<Disk_Group>$($_.VsanDiskGroup)</Disk_Group>
</Disk>
"@) | Out-File $vSANFile -Append
$dn++
}
" </Disks>" | Out-File $vSANFile -Append
#-------------------------------------------------------------------------------------
#vSAN Datastore Table Header and Data
(@"
<vSAN_DS_Info>
<State>$($vSANDS.State)</State>
<Capacity_(GB)>$($vSANDS.CapacityGB)</Capacity_(GB)>
<Free_Space_(GB)>$($vSANDS.FreeSpaceGB)</Free_Space_(GB)>
<ID>$($vSANDS.Id)</ID>
</vSAN_DS_Info>
<vSAN_Storage_Policy>
"@) | Out-File $vSANFile -Append
#-------------------------------------------------------------------------------------
#vSAN Storage Policy Table Header and Data
$vSANPolicy | % { #Get rules set capabilities
(@"
<$($_.Capability)>$($_.value)</$($_.Capability)>
"@) | Out-File $vSANFile -Append
}
(@"
</vSAN_Storage_Policy>
</VSAN>
"@) | Out-File $vSANFile -Append