Highlighted
Contributor
Contributor

Get-View PodStorageDrsEntry.StorageDrsConfig.VmConfig with UpdateViewData()

Jump to solution

Hi,

is it possible to use UpdateViewData() method with Get-View on the ViewType "StoragePod" to Update the data of PodStorageDrsEntry.StorageDrsConfig.VmConfig for the VM names without using another Get-View (Get-View -Id $_.Id -Property Name) calls? The extra Get-View calls cost us some valuable seconds which I would like to save and in almost all other places, UpdateViewData() also works fine. So I think I am missing something or doing something wrong.

Unfortunately I cannot get it to run with UpdateViewData(), f.e.:

$_.UpdateViewData("PodStorageDrsEntry.StorageDrsConfig.VmConfig.Vm.Name")

MhodInvocationExcption: Exception calling "UpdateViewData" with "1" argument(s): ""

Example Code:

$ViewProperties = "Name",

"PodStorageDrsEntry.StorageDrsConfig.PodConfig",

"PodStorageDrsEntry.StorageDrsConfig.VmConfig"


$ViewType = "StoragePod"


(Get-View -ViewType $ViewType -Property $ViewProperties).ForEach(

    {

        $_.UpdateViewData("ChildEntity.Name")

        [PSCustomObject][ordered]@{

            Name           = [string]$_.Name

            Datastores     = ($_.LinkedView.ChildEntity.Name) -join ', '

            DatastoreIds   = ($_.LinkedView.ChildEntity.MoRef) -join ', '

            DrsEnabledVms  = ((@($_.PodStorageDrsEntry.StorageDrsConfig.VmConfig).ForEach( { if ($_.Enabled -eq $true) { Get-View -Id $_.Vm -Property Name } })).Name) -join ', '

            DrsDisabledVms = ((@($_.PodStorageDrsEntry.StorageDrsConfig.VmConfig).ForEach( { if ($_.Enabled -eq $false -or $_.Behavior -match "manual") { Get-View -Id $_.Vm -Property Name } })).Name) -join ', '

        }

    }

)


(I have the same problem for other Api Types (f.e. in ClusterComputeResource -> $_.ConfigurationEx.DrsVmConfig)

(Perhaps LucD​ or mattboren​ can help?)

Thanks in advance,

Eize

0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

The property PodStorageDrsEntry.StorageDrsConfig.VmConfig.VM is an array of MoRefs.

There is no Name property on there, only after you do a Get-View -Id $_.PodStorageDrsEntry.StorageDrsConfig.VmConfig.VM


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

View solution in original post

0 Kudos
7 Replies
Highlighted
User Moderator
User Moderator

The property PodStorageDrsEntry.StorageDrsConfig.VmConfig.VM is an array of MoRefs.

There is no Name property on there, only after you do a Get-View -Id $_.PodStorageDrsEntry.StorageDrsConfig.VmConfig.VM


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

View solution in original post

0 Kudos
Highlighted
Contributor
Contributor

Okay, too bad... Then this is probably already the fastest way to get this overview.

Thanks! Smiley Happy

0 Kudos
Highlighted
User Moderator
User Moderator

You might want to give this one a try, it replaces one if statement with a where method.

It could make it a few jiffies faster :smileygrin:

$ViewProperties = "Name",

"PodStorageDrsEntry.StorageDrsConfig.PodConfig",

"PodStorageDrsEntry.StorageDrsConfig.VmConfig"


$ViewType = "StoragePod"

(Get-View -ViewType $ViewType -Property $ViewProperties).ForEach(

    {

        $_.UpdateViewData("ChildEntity.Name")

        $vms = $_.PodStorageDrsEntry.StorageDrsConfig.VmConfig.where({$_.VM},'Default')

        [PSCustomObject][ordered]@{

            Name           = [string]$_.Name

            Datastores     = ($_.LinkedView.ChildEntity.Name) -join ', '

            DatastoreIds   = ($_.LinkedView.ChildEntity.MoRef) -join ', '

            DrsEnabledVms = ($vms.where({$_.Enabled},'Default').Vm).foreach({Get-View -Id $_ -Property Name}).Name -join ','

            DrsDisabledVms = ($vms.where({-not $_.Enabled},'Default').Vm).foreach({Get-View -Id $_ -Property Name}).Name -join ','

        }

    }

)


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

0 Kudos
Highlighted
Contributor
Contributor

Ah, nice idea. I compared my few lines and yours. Yours are about 20% slower than using the if statement.

I just tested if something like this would be possible: https://blogs.vmware.com/PowerCLI/2011/08/optimize-the-performance-of-powerclis-views.html

0 Kudos
Highlighted
User Moderator
User Moderator

Strange, on my system the times are practically the same.

Could be due to the size of the environment.

Yes, that method with LinkedView should work.
If it will be faster, I don't know


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

0 Kudos
Highlighted
Contributor
Contributor

It could also be due to the Powershell version used, I use the latest Powershell 7.

Somehow I can't get it to work with LinkedView, you can't specify a data type for PodStorageDrsEntry like in the example from the link in my last post. Do you have a tip for me here? (In general the call with UpdateViewData/LinkedView works, but not for VmConfig)

0 Kudos
Highlighted
User Moderator
User Moderator

Could be, I used PSV5.1 on a Windows box.

I'll have a look at the LinkedView, but be warned, I seldom use it :smileygrin:


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

0 Kudos