forked from codyhosterman/powercli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bestpracticechecker.ps1
538 lines (518 loc) · 26.3 KB
/
bestpracticechecker.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
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
#Enter the following required parameters. Log folder directory is just and example, change as needed.
#Put all entries inside the quotes:
#**********************************
$vcenter = ""
$vcuser = ""
$vcpass = ""
$logfolder = "C:\folder\folder\etc\"
#**********************************
<#
Optional parameters. Keep these values at default unless necessary and understood
For a different IO Operations limit beside the Pure Storage recommended value of 1, change $iopsvalue to another integer value 1-1000.
To skip changing host-wide settings for XCOPY Transfer Size and In-Guest UNMAP change $hostwidesettings to $false
For a different minimum path count, change from 4 to another integer. 1-32 (1 is HIGHLY discouraged)
#>
$iopsvalue = 1
$hostwidesettings = $true
$minpaths = 4
<#
*******Disclaimer:******************************************************
This scripts are offered "as is" with no warranty. While this
scripts is tested and working in my environment, it is recommended that you test
this script in a test lab before using in a production environment. Everyone can
use the scripts/commands provided here without any written permission but I
will not be liable for any damage or loss to the system.
************************************************************************
This script will:
-Check for a SATP rule for Pure Storage FlashArrays
-Report correct and incorrect FlashArray rules
-Check for individual devices that are not configured properly
All information logged to a file.
This can be run directly from PowerCLI or from a standard PowerShell prompt. PowerCLI must be installed on the local host regardless.
Supports:
-FlashArray 400 Series and //m
-vCenter 5.0 and later
-PowerCLI 6.3 R1 or later required
For info, refer to www.codyhosterman.com
#>
#Create log folder if non-existent
If (!(Test-Path -Path $logfolder)) { New-Item -ItemType Directory -Path $logfolder }
$logfile = $logfolder + (Get-Date -Format o |ForEach-Object {$_ -Replace ":", "."}) + "checkbestpractices.txt"
write-host "Checking Pure Storage FlashArray Best Practices for VMware on the ESXi hosts in this vCenter. "
write-host "Script log information can be found at $logfile"
add-content $logfile ' __________________________'
add-content $logfile ' /++++++++++++++++++++++++++\'
add-content $logfile ' /++++++++++++++++++++++++++++\'
add-content $logfile ' /++++++++++++++++++++++++++++++\'
add-content $logfile ' /++++++++++++++++++++++++++++++++\'
add-content $logfile ' /++++++++++++++++++++++++++++++++++\'
add-content $logfile ' /++++++++++++/----------\++++++++++++\'
add-content $logfile ' /++++++++++++/ \++++++++++++\'
add-content $logfile ' /++++++++++++/ \++++++++++++\'
add-content $logfile ' /++++++++++++/ \++++++++++++\'
add-content $logfile ' /++++++++++++/ \++++++++++++\'
add-content $logfile ' \++++++++++++\ /++++++++++++/'
add-content $logfile ' \++++++++++++\ /++++++++++++/'
add-content $logfile ' \++++++++++++\ /++++++++++++/'
add-content $logfile ' \++++++++++++\ /++++++++++++/'
add-content $logfile ' \++++++++++++\ /++++++++++++/'
add-content $logfile ' \++++++++++++\'
add-content $logfile ' \++++++++++++\'
add-content $logfile ' \++++++++++++\'
add-content $logfile ' \++++++++++++\'
add-content $logfile ' \------------\'
add-content $logfile 'Pure Storage FlashArray VMware ESXi Best Practices Checker Script v3.0'
add-content $logfile '----------------------------------------------------------------------------------------------------'
if ( !(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) ) {
. “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1” |out-null
}
set-powercliconfiguration -invalidcertificateaction "ignore" -confirm:$false |out-null
if ((Get-PowerCLIVersion).build -lt 3737840)
{
write-host "This version of PowerCLI is too old, version 6.3 Release 1 or later is required (Build 3737840)" -BackgroundColor Red
write-host "Found the following build number:"
write-host (Get-PowerCLIVersion).build
write-host "Terminating Script" -BackgroundColor Red
add-content $logfile "This version of PowerCLI is too old, version 6.3 Release 1 or later is required (Build 3737840)"
add-content $logfile "Found the following build number:"
add-content $logfile (Get-PowerCLIVersion).build
add-content $logfile "Terminating Script"
return
}
try
{
connect-viserver -Server $vcenter -username $vcuser -password $vcpass -ErrorAction Stop |out-null
}
catch
{
write-host "Failed to connect to vCenter" -BackgroundColor Red
write-host $Error
write-host "Terminating Script" -BackgroundColor Red
add-content $logfile "Failed to connect to vCenter"
add-content $logfile $Error
add-content $logfile "Terminating Script"
return
}
write-host "No further information is printed to the screen."
add-content $logfile ('Connected to vCenter at ' + $vcenter)
add-content $logfile '----------------------------------------------------------------------------------------------------'
$hosts= get-vmhost
add-content $logfile "Iterating through all ESXi hosts..."
$hosts | out-string | add-content $logfile
#Iterating through each host in the vCenter
foreach ($esx in $hosts)
{
$esxcli=get-esxcli -VMHost $esx -v2
add-content $logfile "***********************************************************************************************"
add-content $logfile "**********************************NEXT ESXi HOST***********************************************"
add-content $logfile "-----------------------------------------------------------------------------------------------"
add-content $logfile "Working on the following ESXi host:"
add-content $logfile $esx.NetworkInfo.hostname
add-content $logfile $esx.Version
add-content $logfile "-----------------------------------------------------------------------------------------------"
if ($hostwidesettings -eq $true)
{
add-content $logfile "Checking host-wide settings for VAAI and In-Guest UNMAP"
add-content $logfile "-------------------------------------------------------"
$xcopy = $esx | Get-AdvancedSetting -Name DataMover.HardwareAcceleratedMove
if ($xcopy.value -eq 0)
{
add-content $logfile "[****NEEDS ATTENTION****]The VAAI XCOPY (Full Copy) feature is not enabled on this host, it should be enabled."
}
else
{
add-content $logfile "The VAAI XCOPY (Full Copy) feature is correctly enabled on this host."
}
$writesame = $esx | Get-AdvancedSetting -Name DataMover.HardwareAcceleratedInit
if ($writesame.value -eq 0)
{
add-content $logfile "[****NEEDS ATTENTION****]The VAAI WRITESAME (Block Zero) feature is not enabled on this host, it should be enabled."
}
else
{
add-content $logfile "The VAAI WRITESAME (Block Zero) feature is correctly enabled on this host."
}
$atslocking = $esx | Get-AdvancedSetting -Name VMFS3.HardwareAcceleratedLocking
if ($atslocking.value -eq 0)
{
add-content $logfile "[****NEEDS ATTENTION****]The VAAI ATOMIC TEST & SET (Assisted Locking) feature is not enabled on this host, it should be enabled."
}
else
{
add-content $logfile "The VAAI ATOMIC TEST & SET (Assisted Locking) feature is correctly enabled on this host."
}
if (($datastore -ne $null) -and (($esx.version -like ("5.5.*")) -or ($esx.version -like ("6.*"))))
{
$atsheartbeat = $esx | Get-AdvancedSetting -Name VMFS3.useATSForHBOnVMFS5
if ($atsheartbeat.value -eq 0)
{
add-content $logfile "[****NEEDS ATTENTION****]Datastore Heartbeating is not configured to use the VAAI ATOMIC TEST & SET (Assisted Locking) feature, it should be enabled."
}
else
{
add-content $logfile "Datastore Heartbeating is correctly configured to use the VAAI ATOMIC TEST & SET (Assisted Locking) feature."
}
}
$xfersize = $esx | Get-AdvancedSetting -Name DataMover.MaxHWTransferSize
if ($xfersize.value -ne 16384)
{
add-content $logfile "[****NEEDS ATTENTION****]The VAAI XCOPY MaxHWTransferSize for this host is incorrect:"
add-content $logfile $xfersize.value
add-content $logfile "This should be set to 16386 (16 MB)."
}
else
{
add-content $logfile "The VAAI XCOPY MaxHWTransferSize for this host is correct at 16 MB."
}
if ($esx.Version -like "6.0.*")
{
$enableblockdelete = ($esx | Get-AdvancedSetting -Name VMFS3.EnableBlockDelete).Value
if ($enableblockdelete.Value -eq 0)
{
add-content $logfile "[****NEEDS ATTENTION****]EnableBlockDelete is currently disabled but is recommended to be enabled."
}
else
{
add-content $logfile "EnableBlockDelete for this host is correctly enabled."
}
}
else
{
add-content $logfile "The current host is not version 6.0. Skipping EnableBlockDelete check as it is not applicable at this version."
}
}
else
{
add-content $logfile "Not checking host wide settings for VAAI and In-Guest UNMAP due to in-script override"
}
add-content $logfile ""
add-content $logfile ""
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
add-content $logfile "Checking for FlashArray iSCSI targets and verifying their configuration on the host. Only misconfigured iSCSI targets will be reported."
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
$iscsitofix = @()
$flasharrayiSCSI = $false
$targets = $esxcli.iscsi.adapter.target.portal.list.invoke()
$iscsihba = $esx |Get-vmhosthba|where-object {$_.Model -eq "iSCSI Software Adapter"}
$statictgts = $iscsihba | Get-IScsiHbaTarget -type static
foreach ($target in $targets)
{
if ($target.Target -like "*purestorage*")
{
$flasharrayiSCSI = $true
foreach ($statictgt in $statictgts)
{
if ($target.IP -eq $statictgt.Address)
{
$iscsioptions = $statictgt.ExtensionData.AdvancedOptions
foreach ($iscsioption in $iscsioptions)
{
if ($iscsioption.key -eq "DelayedAck")
{
$iscsiack = $iscsioption.value
}
if ($iscsioption.key -eq "LoginTimeout")
{
$iscsitimeout = $iscsioption.value
}
}
if (($iscsiack -eq $true) -or ($iscsitimeout -ne 30))
{
if ($iscsiack -eq $true)
{
$iscsiack = "Enabled"
}
else
{
$iscsiack = "Disabled"
}
$iscsitgttofix = new-object psobject -Property @{
TargetIP = $target.IP
TargetIQN = $target.Target
DelayedAck = $iscsiack
LoginTimeout = $iscsitimeout
}
$iscsitofix += $iscsitgttofix
}
}
}
}
}
if ($iscsitofix.count -ge 1)
{
add-content $logfile ("[****NEEDS ATTENTION****]A total of " + ($iscsitofix | select-object -unique).count + " FlashArray iSCSI targets have one or more errors.")
add-content $logfile "Each target listed has an issue with at least one of the following configurations:"
add-content $logfile (" --The target does not have DelayedAck disabled")
add-content $logfile (" --The target does not have the iSCSI Login Timeout set to 30")
$tableofiscsi = @(
'TargetIP'
@{Label = 'TargetIQN'; Expression = {$_.TargetIQN}; Alignment = 'Left'}
@{Label = 'DelayedAck'; Expression = {$_.DelayedAck}; Alignment = 'Left'}
@{Label = 'LoginTimeout'; Expression = {$_.LoginTimeout}; Alignment = 'Left'}
)
$iscsitofix | ft -property $tableofiscsi -autosize| out-string | add-content $logfile
}
else
{
add-content $logfile "No FlashArray iSCSI targets were found with configuration issues."
}
add-content $logfile ""
add-content $logfile ""
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
add-content $logfile "Checking for Software iSCSI Network Port Bindings."
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
if ($flasharrayiSCSI -eq $true)
{
$iSCSInics = $esxcli.iscsi.networkportal.list.invoke()
$goodnics = @()
$badnics = @()
if ($iSCSInics.Count -gt 0)
{
foreach ($iSCSInic in $iSCSInics)
{
if (($iSCSInic.CompliantStatus -eq "compliant") -and ($iSCSInic.PathStatus -eq "active"))
{
$goodnics += $iSCSInic
}
else
{
$badnics += $iSCSInic
}
}
if ($goodnics.Count -lt 2)
{
add-content $logfile ("Found " + $goodnics.Count + " COMPLIANT AND ACTIVE NICs out of a total of " + $iSCSInics.Count + "NICs bound to this adapter")
$nicstofix = @()
add-content $logfile "[****NEEDS ATTENTION****]There are less than two COMPLIANT and ACTIVE NICs bound to the iSCSI software adapter. It is recommended to have two or more."
if ($badnics.count -ge 1)
{
foreach ($badnic in $badnics)
{
$nictofix = new-object psobject -Property @{
vmkName = $badnic.Vmknic
CompliantStatus = $badnic.CompliantStatus
PathStatus = $badnic.PathStatus
vSwitch = $badnic.Vswitch
}
$nicstofix += $nictofix
}
$tableofbadnics = @(
'vmkName'
@{Label = 'ComplianceStatus'; Expression = {$_.CompliantStatus}; Alignment = 'Left'}
@{Label = 'PathStatus'; Expression = {$_.PathStatus}; Alignment = 'Left'}
@{Label = 'vSwitch'; Expression = {$_.vSwitch}; Alignment = 'Left'}
)
add-content $logfile "The following are NICs that are bound to the iSCSI Adapter but are either NON-COMPLIANT, INACTIVE or both"
$nicstofix | ft -property $tableofbadnics -autosize| out-string | add-content $logfile
}
}
else
{
add-content $logfile ("Found " + $goodnics.Count + " NICs that are bound to the iSCSI Adapter and are COMPLIANT and ACTIVE. No action needed.")
}
}
else
{
add-content $logfile "[****NEEDS ATTENTION****]There are zero NICs bound to the software iSCSI adapter. This is strongly discouraged. Please bind two or more NICs"
}
}
if ($flasharrayiSCSI -eq $false)
{
add-content $logfile "No FlashArray iSCSI targets found on this host"
}
add-content $logfile ""
add-content $logfile ""
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
add-content $logfile "Checking VMware NMP Multipathing configuration for FlashArray devices."
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
$rules = $esxcli.storage.nmp.satp.rule.list.invoke() |where-object {$_.Vendor -eq "PURE"}
$correctrule = 0
$iopsoption = "iops=" + $iopsvalue
if ($rules.Count -ge 1)
{
add-content $logfile ("Found " + $rules.Count + " existing Pure Storage SATP rule(s)")
foreach ($rule in $rules)
{
add-content $logfile "-----------------------------------------------"
add-content $logfile "Checking the following existing rule:"
$rule | out-string | add-content $logfile
$issuecount = 0
if ($rule.DefaultPSP -eq "VMW_PSP_RR")
{
add-content $logfile "This Pure Storage FlashArray rule is configured with the correct Path Selection Policy."
}
else
{
add-content $logfile "[****NEEDS ATTENTION****]This Pure Storage FlashArray rule is NOT configured with the correct Path Selection Policy:"
add-content $logfile $rule.DefaultPSP
add-content $logfile "The rule should be configured to Round Robin (VMW_PSP_RR)"
$issuecount = 1
}
if ($rule.PSPOptions -eq $iopsoption)
{
add-content $logfile "This Pure Storage FlashArray rule is configured with the correct IO Operations Limit."
}
else
{
add-content $logfile "[****NEEDS ATTENTION****]This Pure Storage FlashArray rule is NOT configured with the correct IO Operations Limit:"
add-content $logfile $rule.PSPOptions
add-content $logfile "The rule should be configured to an IO Operations Limit of $iopsvalue"
$issuecount = $issuecount + 1
}
if ($rule.Model -eq "FlashArray")
{
add-content $logfile "This Pure Storage FlashArray rule is configured with the correct model."
}
else
{
add-content $logfile "[****NEEDS ATTENTION****]This Pure Storage FlashArray rule is NOT configured with the correct model:"
add-content $logfile $rule.Model
add-content $logfile "The rule should be configured with the model of FlashArray"
$issuecount = $issuecount + 1
}
if ($issuecount -ge 1)
{
add-content $logfile "[****NEEDS ATTENTION****]This rule is incorrect and should be removed."
add-content $logfile "-----------------------------------------------"
}
else
{
add-content $logfile "This rule is correct."
add-content $logfile "-----------------------------------------------"
$correctrule = 1
}
}
}
if ($correctrule -eq 0)
{
add-content $logfile "[****NEEDS ATTENTION****]No correct SATP rule for the Pure Storage FlashArray is found. You should create a new rule to set Round Robin and an IO Operations Limit of $iopsvalue"
}
else
{
add-content $logfile "A correct SATP rule for the FlashArray exists. No need to create a new one on this host."
}
$devices = $esx |Get-ScsiLun -CanonicalName "naa.624a9370*"
if ($devices.count -ge 1)
{
add-content $logfile ""
add-content $logfile ""
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
add-content $logfile "Checking for existing Pure Storage FlashArray devices and their multipathing configuration."
add-content $logfile "-------------------------------------------------------------------------------------------------------------------------------------------"
add-content $logfile ("Found " + $devices.count + " existing Pure Storage volumes on this host.")
add-content $logfile "Checking their multipathing configuration now. Only listing devices with issues."
add-content $logfile "Checking for Path Selection Policy, Path Count and IO Operations Limit"
add-content $logfile ""
$devstofix = @()
foreach ($device in $devices)
{
$devpsp = $false
$deviops = $false
$devpaths = $false
$devATS = $false
$datastore = $null
if ($device.MultipathPolicy -ne "RoundRobin")
{
$devpsp = $true
$psp = $device.MultipathPolicy
$psp = "$psp" + "*"
}
else
{
$psp = $device.MultipathPolicy
}
$deviceargs = $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get.createargs()
$deviceargs.device = $device.CanonicalName
if ($device.MultipathPolicy -eq "RoundRobin")
{
$deviceconfig = $esxcli.storage.nmp.psp.roundrobin.deviceconfig.get.invoke($deviceargs)
if ($deviceconfig.IOOperationLimit -ne $iopsvalue)
{
$deviops = $true
$iops = $deviceconfig.IOOperationLimit
$iops = $iops + "*"
}
else
{
$iops = $deviceconfig.IOOperationLimit
}
}
if (($device |get-scsilunpath).count -lt $minpaths)
{
$devpaths = $true
$paths = ($device |get-scsilunpath).count
$paths = "$paths" + "*"
}
else
{
$paths = ($device |get-scsilunpath).count
}
$datastore = $esx |Get-Datastore |where-object { $_.ExtensionData.Info.Vmfs.Extent.DiskName -eq $device.CanonicalName }
if (($datastore -ne $null) -and ($esx.version -like ("6.*")))
{
$vmfsargs = $esxcli.storage.vmfs.lockmode.list.CreateArgs()
$vmfsargs.volumelabel = $datastore.name
$vmfsconfig = $esxcli.storage.vmfs.lockmode.list.invoke($vmfsargs)
if ($vmfsconfig.LockingMode -ne "ATS")
{
$devATS = $true
$ATS = $vmfsconfig.LockingMode
$ATS = $ATS + "*"
}
else
{
$ATS = $vmfsconfig.LockingMode
}
}
if ($deviops -or $devpsp -or $devpaths -or $devATS)
{
$devtofix = new-object psobject -Property @{
NAA = $device.CanonicalName
PSP = $psp
IOPSValue = if ($device.MultipathPolicy -eq "RoundRobin"){$iops}else {"N/A"}
PathCount = $paths
ATSMode = if (($datastore -ne $null) -and ($esx.version -like ("6.*"))) {$ATS}else{"N/A"}
}
$devstofix += $devtofix
}
}
if ($devstofix.count -ge 1)
{
add-content $logfile ("[****NEEDS ATTENTION****]A total of " + $devstofix.count + " FlashArray devices have one or more errors.")
add-content $logfile ""
add-content $logfile "Each device listed has an issue with at least one of the following configurations:"
add-content $logfile " --Path Selection Policy is not set to Round Robin (VMW_PSP_RR)"
add-content $logfile (" --IO Operations Limit (IOPS) is not set to the recommended value (" + $iopsvalue + ")")
add-content $logfile (" --The device has less than the minimum recommended logical paths (" + $minpaths + ")")
add-content $logfile (" --The VMFS on this device does not have ATSonly mode enabled.")
add-content $logfile ""
add-content $logfile "Settings that need to be fixed are marked with an asterisk (*)"
$tableofdevs = @(
'NAA'
@{Label = 'PSP'; Expression = {$_.PSP}; Alignment = 'Left'}
@{Label = 'PathCount'; Expression = {$_.PathCount}; Alignment = 'Left'}
@{Label = 'IOPSValue'; Expression = {$_.IOPSValue}; Alignment = 'Left'}
@{Label = 'ATSMode'; Expression = {$_.ATSMode}; Alignment = 'Left'}
)
$devstofix | ft -property $tableofdevs -autosize| out-string | add-content $logfile
}
else
{
add-content $logfile "No devices were found with configuration issues."
}
}
else
{
add-content $logfile "No existing Pure Storage volumes found on this host."
}
add-content $logfile ""
add-content $logfile "Done with the following ESXi host:"
add-content $logfile $esx.NetworkInfo.hostname
add-content $logfile "***********************************************************************************************"
add-content $logfile "**********************************DONE WITH ESXi HOST******************************************"
add-content $logfile "***********************************************************************************************"
add-content $logfile ""
add-content $logfile ""
}
disconnect-viserver -Server $vcenter -confirm:$false
add-content $logfile "Disconnected vCenter connection"