PowerCLI – Disable Storage IO Control and statistics collection

PowerCLI
#  Found  https://vmscribble.com/powercli/powercli-disable-storage-io-control-and-statistics-collection
#  thanks - https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-a-quick-one-line-script-to-disable-SIOC-on-all-Datastores/m-p/2164439
# thanks https://github.com/vmware/PowerCLI-Example-Scripts/blob/master/Scripts/DatastoreSIOCStatistics.ps1


Write-Host  "
This PowerCLI script will Disable Storage I/O Control and statistics collection on all datastores in a SDRS cluster
"

#Variables
$vCenter = Read-Host "Enter the FQDN of the vCenter"
$DSClusterName = Read-Host "Enter the SDRS Cluster Name"

# Connect to the vCenter
Connect-VIServer $vCenter | Out-Null

# List Datastores inside the SDRS Cluster
$DS = Get-DatastoreCluster -Name $DSClusterName | Get-Datastore

# https://vdc-repo.vmware.com/vmwb-repository/dcr-public/6b586ed2-655c-49d9-9029-bc416323cb22/fa0b429a-a695-4c11-b7d2-2cbc284049dc/doc/vim.StorageResourceManager.IORMConfigSpec.html

$viewStorageRM = Get-View -Id "StorageResourceManager-StorageResourceManager" 
$spec1 = New-Object VMware.Vim.StorageIORMConfigSpec -Property @{"Enabled" = $false}
$spec2 = New-Object VMware.Vim.StorageIORMConfigSpec -Property @{"StatsCollectionEnabled" = $false}
$spec3 = New-Object VMware.Vim.StorageIORMConfigSpec -Property @{"StatsAggregationDisabled" = $true}


Write-Output "Changing datastore: $($DS.Name)"

# Pause as added to resolve - The operation is not allowed in the current state
$DS | %{$viewStorageRM.ConfigureDatastoreIORM_Task($_.Id, $spec1)}
Start-Sleep -seconds 5
$DS | %{$viewStorageRM.ConfigureDatastoreIORM_Task($_.Id, $spec2)}
Start-Sleep -seconds 5
$DS | %{$viewStorageRM.ConfigureDatastoreIORM_Task($_.Id, $spec3)}


# Disconnect from the vCenter
Disconnect-VIServer $vCenter -Confirm:$false
Goal
Testing
The Script
#  Found  https://vmscribble.com/powercli/powercli-disable-storage-io-control-and-statistics-collection
#  thanks - https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Need-a-quick-one-line-script-to-disable-SIOC-on-all-Datastores/m-p/2164439
# thanks https://github.com/vmware/PowerCLI-Example-Scripts/blob/master/Scripts/DatastoreSIOCStatistics.ps1


Write-Host  "
This PowerCLI script will Disable Storage I/O Control and statistics collection on all datastores in a SDRS cluster
"

#Variables
$vCenter = Read-Host "Enter the FQDN of the vCenter"
$DSClusterName = Read-Host "Enter the SDRS Cluster Name"

# Connect to the vCenter
Connect-VIServer $vCenter | Out-Null

# List Datastores inside the SDRS Cluster
$DS = Get-DatastoreCluster -Name $DSClusterName | Get-Datastore

# https://vdc-repo.vmware.com/vmwb-repository/dcr-public/6b586ed2-655c-49d9-9029-bc416323cb22/fa0b429a-a695-4c11-b7d2-2cbc284049dc/doc/vim.StorageResourceManager.IORMConfigSpec.html

$viewStorageRM = Get-View -Id "StorageResourceManager-StorageResourceManager" 
$spec1 = New-Object VMware.Vim.StorageIORMConfigSpec -Property @{"Enabled" = $false}
$spec2 = New-Object VMware.Vim.StorageIORMConfigSpec -Property @{"StatsCollectionEnabled" = $false}
$spec3 = New-Object VMware.Vim.StorageIORMConfigSpec -Property @{"StatsAggregationDisabled" = $true}


Write-Output "Changing datastore: $($DS.Name)"

# Pause as added to resolve - The operation is not allowed in the current state
$DS | %{$viewStorageRM.ConfigureDatastoreIORM_Task($_.Id, $spec1)}
Start-Sleep -seconds 5
$DS | %{$viewStorageRM.ConfigureDatastoreIORM_Task($_.Id, $spec2)}
Start-Sleep -seconds 5
$DS | %{$viewStorageRM.ConfigureDatastoreIORM_Task($_.Id, $spec3)}


# Disconnect from the vCenter
Disconnect-VIServer $vCenter -Confirm:$false