VMware Cloud Community
fsanders
Contributor
Contributor
Jump to solution

Script to check for VM Automation Level in a Datastore Cluster

Is there a way to find out when the "Automation Level" of a VM is set to anything other than "Default (Fully Automated)"?  See the 3rd VM in the screenshot as an example.  I would like to add a check for this in a Daily Health Check script. 

Datastore-Cluster.jpg

I didn't see a value for Automation Level when performing a Get-DatastoreCluster | Get-Member

Thanks!

Fred

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Oops, misread your question obviously.

Try this

function Get-StoragePod{
<#
.SYNOPSIS  Find a DatastoreCluster
.
DESCRIPTION The function will return a StoragePod object.   This is the server-side object used by vSphere for a  DatastoreCluster. .NOTES  AuthorLuc Dekens
.PARAMETER Name  The name of the DatastoreCluster
.EXAMPLE
 
PS> Get-StoragePod
.
EXAMPLE
 
PS> Get-StoragePod -Name "SDC*" #>   param(   [CmdletBinding()]   [parameter(Position = 0, ValueFromPipeline = $true)]   [string]$Name = "*"  )   begin{    function Get-StoragePodInternal{      param(      [CmdletBinding()]      [parameter(Mandatory = $true,ValueFromPipeline = $true)]      [VMware.Vim.Folder]$Folder     )      $Folder.ChildEntity | %{        if($_.Type -eq "StoragePod"){          Get-View -Id $_       }        elseif($_.Type -eq "Folder"){          Get-View -Id $_ | Get-StoragePodInternal
       }      }     }   }  
process{     Get-Folder -Name datastore | %{       Get-StoragePodInternal -Folder $_.ExtensionData
    } | where {$_.Name -like $Name}   } } $dsc = Get-StoragePod -Name MyDSC
$dsc
.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {$_.Enabled} | Select @{N="VM";E={(Get-View $_.VM).Name}},Enabled,IntraVmAffinity


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Did you check Script to report on virtual machine automation level in DRS

That property is in the VirtualMachine object returned by Get-VM


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

fsanders
Contributor
Contributor
Jump to solution

I did see where you get the DRS Automation Level using Get-VM, but I am looking for the Storage DRS Automation Level for a VM in a Datastore Cluster.  We are using Datastore Clusters and normally the Automation Level setting is "Default (Fully Automated)", but if someone happens to Manualy Storage vMotion a VM in the Datastore Cluster, it will set the Automation Level to "Disabled" for Storage DRS.  We can get around the issue by putting it in our procedures to check this after a manual Storage vMotion, but I like to make sure that it gets checked to be safe.  If there was a SDrsAutomationLevel property, that would work. 

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Oops, misread your question obviously.

Try this

function Get-StoragePod{
<#
.SYNOPSIS  Find a DatastoreCluster
.
DESCRIPTION The function will return a StoragePod object.   This is the server-side object used by vSphere for a  DatastoreCluster. .NOTES  AuthorLuc Dekens
.PARAMETER Name  The name of the DatastoreCluster
.EXAMPLE
 
PS> Get-StoragePod
.
EXAMPLE
 
PS> Get-StoragePod -Name "SDC*" #>   param(   [CmdletBinding()]   [parameter(Position = 0, ValueFromPipeline = $true)]   [string]$Name = "*"  )   begin{    function Get-StoragePodInternal{      param(      [CmdletBinding()]      [parameter(Mandatory = $true,ValueFromPipeline = $true)]      [VMware.Vim.Folder]$Folder     )      $Folder.ChildEntity | %{        if($_.Type -eq "StoragePod"){          Get-View -Id $_       }        elseif($_.Type -eq "Folder"){          Get-View -Id $_ | Get-StoragePodInternal
       }      }     }   }  
process{     Get-Folder -Name datastore | %{       Get-StoragePodInternal -Folder $_.ExtensionData
    } | where {$_.Name -like $Name}   } } $dsc = Get-StoragePod -Name MyDSC
$dsc
.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {$_.Enabled} | Select @{N="VM";E={(Get-View $_.VM).Name}},Enabled,IntraVmAffinity


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
fsanders
Contributor
Contributor
Jump to solution

I really appreciate your Help on this!  You got me on the right track with your script.  If I change the following:

$dsc.PodStorageDrsEntry.StorageDrsConfig.VmConfig | 
where {$_.Enabled} | Select @{N="VM";E={(Get-View $_.VM).Name}},Enabled,IntraVmAffinity

To This:
 

$dsc.PodStorageDrsEntry.StorageDrsConfig.VmConfig | where {$_.Enabled -match "False"} | Select @{N="VM";E={(Get-View $_.VM).Name}},Enabled,IntraVmAffinity

It lists the VMs with the Storage DRS Automation Level not Enabled, which is exactly what I want.  I always seem to learn so much from your scripts. 

Thanks Again!

Fred

Reply
0 Kudos
Onthax
Contributor
Contributor
Jump to solution

Thanks for this script, it has helped me immensely.

Any ideas on how to change the storagedrs automation level of a VM once you have the list?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since there are no cmdlets to configure SDRS in the current PowerCLI build, you will have to fall back on the SDK API.

In this case the ConfigureStorageDrsForPod_Task method will do the task.

In the StorageDrsConfigSpec object, that you pass to the method as one of the parameters, you can configure the SDRS behaviour for individual VMs.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Onthax
Contributor
Contributor
Jump to solution

Thanks for the prompt response.

Will have to read up on it, still new to powershell and powercli :^ )

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Let me know if you can create a working script for this, otherwise I'll see if I can throw together a couple of lines.

Perhaps it would be better to create a new thread for that question.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Dumptruck
Contributor
Contributor
Jump to solution

Anybody know if a cmdlet for this will appear in a future release?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I doubt that VMware will make the PowerCLI roadmap public.

But I'm sure that the new PM is following these threads and will take note of all requests.

The speed in which they will eventually be implemented is something else :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos