From 1b41e221161e5d2c45afd594954b341e980fff6d Mon Sep 17 00:00:00 2001 From: Kyle Ruddy Date: Thu, 8 Dec 2016 11:44:03 -0500 Subject: [PATCH] Datastore SIOC Statistics Collection Functions Created two functions to monitor and manage the SIOC statistic collection of a datastore --- Scripts/DatastoreSIOCStatistics.ps1 | 108 ++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Scripts/DatastoreSIOCStatistics.ps1 diff --git a/Scripts/DatastoreSIOCStatistics.ps1 b/Scripts/DatastoreSIOCStatistics.ps1 new file mode 100644 index 0000000..a407506 --- /dev/null +++ b/Scripts/DatastoreSIOCStatistics.ps1 @@ -0,0 +1,108 @@ +function Get-DatastoreSIOCStatCollection { +<# +.SYNOPSIS + Gathers information on the status of SIOC statistics collection for a datastore +.DESCRIPTION + Will provide the status on a datastore's SIOC statistics collection +.NOTES + Author: Kyle Ruddy, @kmruddy, thatcouldbeaproblem.com +.PARAMETER Datastore + Datastore to be ran against +.EXAMPLE + Get-DatastoreSIOCStatCollection -Datastore ExampleDatastore + Retreives the status of SIOC statistics collection for the provided datastore +#> +[CmdletBinding()] + param( + [Parameter(Mandatory=$true,Position=0,ValueFromPipelineByPropertyName=$true)] + $Datastore + ) + + Process { + + #Collect information about the desired datastore/s and verify existance + $ds = Get-Datastore $datastore -warningaction silentlycontinue -erroraction silentlycontinue + if (!$ds) {Write-Warning -Message "No Datastore found"} + else { + + $report = @() + + #Loops through each datastore provided and feeds back information about the SIOC Statistics Collection status + foreach ($item in $ds) { + + $tempitem = "" | select Name,SIOCStatCollection + $tempitem.Name = $item.Name + $tempitem.SIOCStatCollection = $item.ExtensionData.IormConfiguration.statsCollectionEnabled + $report += $tempitem + + } + + #Returns the output to the user + return $report + + } + + } + +} + + +function Set-DatastoreSIOCStatCollection { +<# +.SYNOPSIS + Configures the status of SIOC statistics collection for a datastore +.DESCRIPTION + Will modify the status on a datastore's SIOC statistics collection +.NOTES + Author: Kyle Ruddy, @kmruddy, thatcouldbeaproblem.com +.PARAMETER Datastore + Datastore to be ran against +.EXAMPLE + Set-DatastoreSIOCStatCollection -Datastore ExampleDatastore -Enable $true + Enables SIOC statistics collection for the provided datastore +#> +[CmdletBinding(SupportsShouldProcess)] + param( + [Parameter(Mandatory=$true,Position=0,ValueFromPipelineByPropertyName=$true)] + $Datastore, + [Switch]$Enable, + [Switch]$Disable + ) + + Process { + + #Collect information about the desired datastore/s and verify existance + $ds = Get-Datastore $datastore -warningaction silentlycontinue -erroraction silentlycontinue + if (!$ds) {Write-Warning -Message "No Datastore found"} + else { + + $report = @() + + #Loops through each datastore provided and modifies the SIOC Statistics Collection status + foreach ($dsobj in $ds) { + + $_this = Get-View -id 'StorageResourceManager-StorageResourceManager' + $spec = New-Object vmware.vim.storageiormconfigspec + + if ($Enable) { + + $spec.statsCollectionEnabled = $true + + } elseif ($Disable) { + + $spec.statsCollectionEnabled = $false + + } + + $_this.ConfigureDatastoreIORM_Task($dsobj.ExtensionData.MoRef,$spec) | out-null + start-sleep -s 1 + $report += Get-View -Id $dsobj.ExtensionData.MoRef -Property Name,Iormconfiguration.statsCollectionEnabled | select Name,@{N='SIOCStatCollection';E={$_.Iormconfiguration.statsCollectionEnabled}} + + } + + #Returns the output to the user + return $report + } + } + +} \ No newline at end of file