haripetrov
Contributor
Contributor

How to use Get-View instead of Get-VM for BusSharingMode of a VM

Again, another question related with Get-View. I searched a lot for documentation but still I don't get the logic how to find the right properties which I need to use.

In this case I need to transfer this one:

Get-VM | Get-ScsiController | Where-Object {$_.BusSharingMode -eq ˜Physical"} | Select {$_.Parent.Name}, BusSharingMode

into:

Get-View -ViewType VirtualMachine -Property Name,Config.NameofthePropertyforBusSharingMode

I will be grateful if someone could provide a documentation (or at least give me a clue what to read to get oriented) about these properties and their format so that they can be used for Get-View.

The closest thing which I found is this one: http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.VirtualMachine.html and the VirtualMachineConfigInfo: http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigInfo.htmlhttp://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigInfo.html
I guess that in this case we are talking about VirtualHardware (SCSI controller): http://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.VirtualHardware.html and still I cannot make the connection. Smiley Happy

Reply
0 Kudos
LucD
Leadership
Leadership

It is all documented in the VMware vSphere API Reference, but as the title states, it is a reference.

The vSphere Web Services SDK Programming Guide is intendedas a learning guide.


The only non-VMware book that explains a bit more about the vSphere API and the objects is the book by Steve Jin, called VMware VI and vSphere SDK: Managing the VMware Infrastructure and vSphere

It is written for Java developers, but it explains the basic concepts.

In this specific question, you need to know that all the devices connected to a VM can be found in Config.Hardware.Device.

It's a matter of looping through the devices and extracting the virtual SCSI controllers that also have physical bus sharing active.

Once you have that, it's simple to extract the properties.

foreach($vm in Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device){

    $scsi = $vm.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualSCSIController] -and $_.SharedBus -eq 'physicalSharing'}

    if($scsi){

        $scsi | Select @{N='VM';E={$vm.Name}},

            @{N='Controller';E={$_.DeviceInfo.Label}},

            @{N='BusSharingMode';E={$_.SharedBus}}

    }

}


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

View solution in original post

Reply
0 Kudos
haripetrov
Contributor
Contributor

Thank you! Now is much clear for me.

I will try to spend more time on this.

Reply
0 Kudos