-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDRS-Reset-VM-overrides.ps1
73 lines (61 loc) · 2.46 KB
/
SDRS-Reset-VM-overrides.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
<#
.SYNOPSIS
Re-Enable SDRS on all VMs associated with a SDRS cluster
.DESCRIPTION
Reset overrides for SDRSAutomationLevel & KeepVMDKsTogether.
SDRS must be enabled set to FullyAutomated for it to loadbalance VMs on SDRS datastores
.INPUTS
n/a
.OUTPUTS
Outputs to screen
.NOTES
website: www.amikkelsen.com
Author: Anders Mikkelsen
Creation Date: 2020-08-18
Tested on vSphere 6.7 U3
1. Change <vcenter server> to you own vCenter
2. Change <SDRS cluster name> to your own SDRS cluster
Thanks to Ryanjan & Vikas Shitole
https://ryanjan.uk/2018/07/30/storage-drs-and-powercli-part-1-get-vm-overrides/
https://github.com/vThinkBeyondVM/vThinkBVM-scripts/blob/master/Powershell-PowerCLI/SDRSVmOverrides.ps1
#>
cls
$strvCenter = "<vcenter server>"
$strSDRSCluster = "<SDRS cluster name>"
connect-viserver $strvCenter
#$StoragePod = Get-View -ViewType "StoragePod" -Filter @{"Name" = $strSDRSCluster} # Without RegEx anchor points, filter acts like a wildcard
$StoragePod = Get-View -ViewType "StoragePod" -Filter @{"Name" = "^$strSDRSCluster$"} # RegEx anchor points added, for Exact Match
#$StoragePod.PodStorageDrsEntry.StorageDrsConfig.VmConfig
if($StoragePod.Count -eq 1)
{
$VMOverrides = $StoragePod.PodStorageDrsEntry.StorageDrsConfig.VmConfig | Where-Object {
-not (
($_.Enabled -eq $null) -and
($_.IntraVmAffinity -eq $null)
)
}
foreach ($Override in $VMOverrides) {
$row = '' | select VMName
$vmMo = Get-View $Override.Vm
if($Override.Enabled -ne $null -or $Override.IntraVmAffinity -ne $null){
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$spec.vmConfigSpec = New-Object VMware.Vim.StorageDrsVmConfigSpec[] (1)
$spec.vmConfigSpec[0] = New-Object VMware.Vim.StorageDrsVmConfigSpec
$spec.vmConfigSpec[0].operation = 'add'
$spec.vmConfigSpec[0].info = New-Object VMware.Vim.StorageDrsVmConfigInfo
$spec.vmConfigSpec[0].info.enabled = $null
$spec.vmConfigSpec[0].info.vm = $Override.Vm;
$spec.vmConfigSpec[0].info.IntraVmAffinity = $null;
$_this = Get-View -Id 'StorageResourceManager-StorageResourceManager'
$_this.ConfigureStorageDrsForPod_Task($StoragePod.MoRef, $spec, $true)
Write-Host "SDRS is re-enabled on this VM :" $vmMo.Name
}
else{
Write-Host "SDRS was already set to Default on VM :" $vmMo.Name
}
}
}
else{
Write-Host "Found $($StoragePod.Count) storage clusters... Only expection 1" -ForegroundColor Red
}
disconnect-viserver * -confirm:$false