forked from jasemccarty/Vsan-Settings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vsan-SetSwapChunkSize.ps1
154 lines (114 loc) · 4.33 KB
/
Vsan-SetSwapChunkSize.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
<#==========================================================================
Script Name: Vsan-SetSwapChunkSize.ps1
Created on: 12/12/2017
Created by: Jase McCarty
Github: http://www.github.com/jasemccarty
Twitter: @jasemccarty
Website: http://www.jasemccarty.com
===========================================================================
.DESCRIPTION
This script will go through a single host, or each host in a designated cluster,
and set /Mem/SwapExtendChunkSizeInMB to either 0 or 65536
Used to mitigate KB 2150316
https://kb.vmware.com/kb/2150316
Works with PowerCLI 6.5.4 and vSAN 6.6
Syntax is:
To Set to Max
Vsan-SetSwapChunkSize.ps1 -Target <Target> -Type <cluster/host> -ChunkSize max
To Set to Default
Vsan-SetSwapChunkSize.ps1 -Target <Target> -Type <cluster/host> -ChunkSize default
.Notes
This is only applicable to ESXi hosts with vSAN 6.5 or greater
#>
# Set our Parameters
[CmdletBinding()]Param(
[Parameter(Mandatory=$True)]
[string]$Target,
[Parameter(Mandatory = $true)]
[ValidateSet('cluster','host')]
[String]$Type,
[Parameter(Mandatory = $true)]
[ValidateSet('max','default')]
[String]$ChunkSize
)
# Must be connected to vCenter Server 1st
# Connect-VIServer
# Check to ensure we have either enable or disable, and set our values/text
Switch ($ChunkSize) {
"max" {
$ChunkSizeValue = "0"
$ChunkSizeText = "ChunkSize set to Max"
}
"default" {
$ChunkSizeValue = "65536"
$ChunkSizeText = "ChunkSize set to Default"
}
}
Switch ($Type) {
"cluster" {
# Get the Cluster Name
$Cluster = Get-Cluster -Name $Target
# Display the Cluster
Write-Host Cluster: $($Cluster.name)
# If the Cluster has VSAN Enabled, then proceed
if ($Cluster.VsanEnabled){
# Cycle through each ESXi Host in the cluster
Foreach ($ESXHost in ($Cluster |Get-VMHost |Sort Name)){
# Grab EsxCLI content to check for proper host version
$esxcli = Get-EsxCli -VMHost $ESXHost -V2
# Grab the major host version
$esxmajor = $esxcli.system.version.get.invoke().version
# Grab the update version
$esxupdate = $esxcli.system.version.get.invoke().update
# Make sure a version 6.5.0 host is being checked
If ($esxmajor -ge "6.5.0") {
# Get the current setting for SwapExtendChunkSizeInMB
$ChunkSizeSetting = Get-AdvancedSetting -Entity $ESXHost -Name "Mem.SwapExtendChunkSizeInMB"
# If the chunk size is different than the requested setting, set them to the opposite
If($ChunkSizeSetting.value -ne $ChunkSizeValue){
# Show that host is being updated
Write-Host "Updating Swap ChunkSize Setting for $ESXHost"
$ChunkSizeSetting | Set-AdvancedSetting -Value $ChunkSizeValue -Confirm:$false
} else {
# Show that the host is already set to the value requested
Write-Host "$ESXhost is already configured for $ChunkSizeText"
}
} else {
Write-Host "$ESXhost not version 6.5 or higher - Exiting"
Exit
}
}
} else {
Write-Host "vSAN Not Enable on Cluster $Cluster.Name - Exiting"
}
}
"host" {
# Get the Host Name
$ESXhost = Get-VMHost -Name $Target
# Display the Cluster
Write-Host Host: $($ESXhost.name)
# Grab EsxCLI content to check for proper host version
$esxcli = Get-EsxCli -VMHost $ESXHost
# Grab the major host version
$esxmajor = $esxcli.system.version.get.invoke().version
# Grab the update version
$esxupdate = $esxcli.system.version.get.invoke().update
# Make sure a version 6.5.0 host is being checked
If ($esxmajor -ge "6.5.0") {
# Get the current setting for SwapExtendChunkSizeInMB
$ChunkSizeSetting = Get-AdvancedSetting -Entity $ESXHost -Name "Mem.SwapExtendChunkSizeInMB"
# If the chunk size is different than the requested setting, set them to the opposite
If($ChunkSizeSetting.value -ne $ChunkSizeValue){
# Show that host is being updated
Write-Host "Updating Swap ChunkSize Setting for $ESXHost"
$ChunkSizeSetting | Set-AdvancedSetting -Value $ChunkSizeValue -Confirm:$false
} else {
# Show that the host is already set to the value requested
Write-Host "$ESXhost is already configured for $ChunkSizeText"
}
} else {
# Show that the host is already set to the value requested
Write-Host "$ESXhost is not 6.5 or higher"
}
}
}