VMware Cloud Community
PoshTechGuyTJ
Enthusiast
Enthusiast
Jump to solution

Storage DRS recommendations

Is there a way with PowerCLI to get the Storage DRS recommendations?

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can get the Storage DRS recommendations for all of your datastore clusters with the following PowerCLI command:

Get-DatastoreCluster | Select Name,@{Name='DrsRecommendation';Expression={$_.ExtensionData.PodStorageDrsEntry.Recommendation}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
3 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can get the Storage DRS recommendations for all of your datastore clusters with the following PowerCLI command:

Get-DatastoreCluster | Select Name,@{Name='DrsRecommendation';Expression={$_.ExtensionData.PodStorageDrsEntry.Recommendation}}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
PoshTechGuyTJ
Enthusiast
Enthusiast
Jump to solution

Thank you Very Much. this is supper helpful. I took what you did and created a cmdlet out of it. Just pass it the Datastore Cluster object (get-datastorecluster) you want to get recommendations on.

I tried using the DatastoreClusterImpl type on the parameter but it received an error so the parameter is not type defined.  Don't know why but Error text is below the function if you want to reproduce. .

function Get-DSClusterDRSRecommendation

{

    [CmdletBinding()]

    Param(

        [Parameter(Mandatory=$true,Position=0)]

        $DatastoreCluster

    )


    BEGIN{}

    PROCESS

    {

        $DRSStorage = $DSCluster | Select Name,@{Name='DrsRecommendation';Expression={$_.ExtensionData.PodStorageDrsEntry.Recommendation}}

        foreach ($Cluster in $DRSStorage)

        {

            foreach ( $Recommendation in $Cluster.DrsRecommendation)

            {

                $hash = [ordered]@{'DatastoreCluster'= $Cluster.Name;

                                   'ComputerName'= (get-view -Id $Recommendation.Action.VM).name ;

                                   'Reason'=$Recommendation.ReasonText;

                                   'Source'= (get-view -Id $Recommendation.Action.Source).Name ;

                                   'Destination'= (get-view -Id $Recommendation.Action.Destination).name;

                                   'AllData'= $Recommendation}

                New-Object -TypeName PSObject -Property $hash

            }

        }

    }

    END{}

}

If you add [VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.DatastoreClusterImpl[]] in front of $DatastoreCluster in the Param definition you get the following error

Get-DSClusterDRSRecommendation : Unable to find type

[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.DatastoreClusterImpl]: make sure that the assembly containing

this type is loaded.

At line:1 char:1

+ Get-DSClusterDRSRecommendation $DSCluster

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (VMware.VimAutom...toreClusterImpl:TypeName) [], RuntimeException

    + FullyQualifiedErrorId : TypeNotFound

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Instead of

[VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.DatastoreClusterImpl[]]

you should use:

[VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.DatastoreCluster[]]

If found this by looking at the type that is used by the DatastoreCluster parameter of the Remove-DatastoreCluster cmdlet. You can find this type by using the following PowerCLI command:

((Get-Command -Name Remove-DatastoreCluster).ParameterSets.Parameters | Where-Object {$_.Name -eq 'DatastoreCluster'}).ParameterType.FullName

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos