Get - view ClusterComputeResource vs StoragePod

The following example of a loop in the cluster/host/vm to PowerCLI LinkedView - a Simple example, I found. The beautiful Hippo

$VMArray = @)

$ClusterArray = get-view ViewType - ClusterComputeResource

$ClusterArray | % {

$_. UpdateViewData ("$host.name", "Host.VM.Name")

$ClusterName = $_. Name

$_. LinkedView.Host | % {

$HostName = $_. Name

$_. LinkedView.VM | % {

$VMName = $_. Name

$VMArray += new-Object - TypeName PSObject - Prop)

@{'Clusters' = $ClusterName;

"Home" = $HostName;

'Name' = $VMName

}

)

}

}

}

I tried the equivalent code for the storage of cluster/datastore/vm

$DSVMArray = @)

$DSClusterArray = get-view ViewType - StoragePod

$DSClusterArray | % {

$_. UpdateViewData ("ChildEntity.Name", "ChildEntity.VM.Name")

$DSClusterName = $_. Name

$_. LinkedView.ChildEntity | % {

$DSName = $_. Name

$_. LinkedView.VM | % {

$VMName = $_. Name

$DSVMArray += new-Object - TypeName PSObject-Prop)

@{'DSCluster' = $DSClusterName;

'Datastore' = $DSName;

"VM" = $VMName;

}

)

}

}

}

But this error

Exception by calling 'UpdateViewData' with '2' or the arguments: "the path specified."

is not correct. Item "vM" does not exist. »

Online: 4 char: 5

+     $_. UpdateViewData ("ChildEntity.Name", "ChildEntity.VM.Name")

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

+ CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)

+ FullyQualifiedErrorId: ArgumentException

The data structures are the same for me.  Could someone please explain the error?

Cannot use UpdateViewData if properties can be null.  In my case I have warehouses of data with no VM so I can not UpdateViewData ("ChildEntity.VM.Name").

$DSVMArray = @)

$DSClusterArray = get-view ViewType - StoragePod

$DSClusterArray | % {

$DSCluster = $_

$DSCluster.UpdateViewData ("ChildEntity.Name")

$DSClusterName = $DSCluster.Name

If ($DSCluster.LinkedView.ChildEntity.VM.Count - gt 0) {}

$DSCluster.LinkedView.ChildEntity.UpdateViewData ("VM. Name")

}

$DSCluster.LinkedView.ChildEntity | %{

$DSName = $_. Name

$_. LinkedView.VM | %{

$VMName = $_. Name

$DSVMArray += new-Object - TypeName PSObject-Prop)

@{'DSCluster' = $DSClusterName;

'Datastore' = $DSName;

"VM" = $VMName;

}

)

}

}

}

Tags: VMware

Similar Questions

  • Get-view SearchRoot when duplicate. MoRef exists

    I created a script to list the details of the bunch and I thought I would faster by using get - view instead of the Get command for each object.  I came across a problem on line 14.  It seems that I have data centers in different virtual centers with the same. MoRef values.  Not sure how I can script around that.

    Note that this script below is a global script version

    $csvreport = @()
    $ClusterList=@()
    $OutputFile="C:\Temp\looptesting.csv"
    $Date=Get-Date -Format d
    
    
    
    
      foreach ($virtualcenter in $DefaultVIServers) {
    
    
      ForEach ($DC in (Get-View -ViewType  Datacenter -Server $virtualcenter)){
    
      Foreach ($cluster in (Get-View -ViewType ClusterComputeResource -SearchRoot $DC.MoRef)){
    
      $ClusterList = "" |select-object "Collection Date","Virtual Center",DataCenter,Cluster
    
      $ClusterList."Collection Date"=$Date
      $ClusterList."Virtual Center"=$virtualcenter
      $ClusterList.DataCenter=$DC.Name
      $ClusterList.Cluster=$cluster.Name
    
      $csvreport += $ClusterList 
      }
      }
      }
    
    
    
    
    $csvreport |export-csv -NoTypeinformation $OutputFile
    

    Can't you just use the Server parameter on line 14, as you did on line 12?

  • show the parent object of get - view - ViewType HostSystem

    I want to change the code snippet below (http://kb.vmware.com/kb/1012514) to include the parent object.

    Notice-EEG - ViewType HostSystem-Property Name, Config.Product. Select Name, {$_.} Config.Product.FullName}, {$_.} Config.Product.Build} | FT-auto

    When I run the modified version, I get 'ComputeResource-domain-sNNNN' or 'ClusterComputeResource-field-cNNN' in the Parent column. If I make one

    Get-Cluster ClusterComputeResource-field-cNNN

    I get the name of one of our groups. So I tried variations of the following, and I still can't get a good Parent.

    C:\ PowerCLI > notice-EEG - ViewType HostSystem-name of the property, Config.Product, Parent | Select Name, {$_.} Config.Product.FullName}, {$_.} Config. Product.Build}, ($_.) Parent | Get-cluster) | Sort - the name of the property. FT-auto

    Select: cannot convert System.Object [] to one of the following types {System.String, System.Management.Automation.ScriptBlock}.

    At line: 1 char: 72

    + view the GET - ViewType HostSystem-name of the property, Config.Product, Parent | Select Na...

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

    + CategoryInfo: InvalidArgument: (:)) [Select-Object], NotSupportedException)

    + FullyQualifiedErrorId: DictionaryKeyUnknownType, Microsoft.PowerShell.Commands.SelectObjectCommand

    PowerCLI C:\ >

    I realize that it does not help that, in some cases Parent will be a cluster object and in other cases it will be an object Folder or Data Center. I also tried

    .... $( if ( $_. Parent) {get-cluster-id $_.} Parent})

    .... ( if ( $_. Parent) {get-cluster-id $_.} Parent})

    .... (get-cluster-name ($_.)) Parent). Name)

    .... (get-cluster-name [string]($_.)) Parent). Name)

    (1) if I'm only looking on with parents of cluster hosts, is there a way to ignore all others?

    (2) how can I get the name of the parent cluster?

    Try like this

    Get-view ViewType - HostSystem-name of the property, Config.Product, Parent |

    Select Name,

    @{N = ' product'; E={$_. Config.Product.FullName}},

    @{N = 'Build'; E={$_. Config.Product.Build}},

    @{N = "Cluster"; E = {}

    $parent = get-view-Id $_. Parent - the Parent property name

    While ($parent - isnot [VMware.Vim.ClusterComputeResource] - and $parent. Parent) {}

    $parent is get-view-Id $parent. Parent - the Parent property name

    }

    If ($parent - is [VMware.Vim.ClusterComputeResource]) {}

    $parent. Name}}} |

    Format-Table-auto

  • Using filters and Get - view to find virtual machines with a specific guest operating system.

    I have the following code snippet to find all virtual machines with the updated OS to ' Red Hat Enterprise Linux * "prompt. It does not work. If the filter is left out, I find myself with all virtual machines.

    The immediate question is the specs for the game ' Red Hat Enterprise Linux. " Originally from the "Performance Difference between GET - VM and GET-VIEW")

    http://www.batchworks.de/performance-difference-between-get-VM-and-get-view/ ).

    $ClusterFilter = Get-View -ViewType ClusterComputeResource -Property Name -Filter @{“Name” = $ClusterName } | select -ExpandProperty MoRef

    $VirtualMachines = Get-View -ViewType VirtualMachine -Property Config -SearchRoot $ClusterFilter


    The biggest problem for me is to understand for Get-View filter. I was capable of a bit of insight to gleen from the URL below, but I think what Miss me is the reference (Microsoft) for what is happening to the right of the equal sign. What is the correct terminology for this type of query expression / where the syntax is 'left' = 'straight' and keywords such as "-match" are not allowed.

    http://purple-screen.com/?Cat=3

    VMware vSphere 5.1

    http://Wannemacher.us/?p=259

    Regular expressions with Windows PowerShell

    Right in the filter expression is an RegEx expression, please allow for characters before and after the word Linux.

    And the name of the OS is Config.GuestFullName.

    I corrected the entries more early as well.

    $ClusterName = "^MyCluster$"$ClusterFilter = get-view -ViewType ClusterComputeResource -Property Name -Filter @{"Name" = $ClusterName } | select -ExpandProperty MoRefWrite-Host $ClusterFilter
    
    $VirtualMachinesNoFilter   = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter $VirtualMachinesWithFilter = Get-View -ViewType VirtualMachine -Property Name,Config -SearchRoot $ClusterFilter -Filter @{"Config.GuestFullName"=".*Linux.*"}
    
  • PowerCLI: Get - view filters and OR conditions

    Hi all

    I'm little a beginner when it comes to tools from command-line and scripting in general, but I was playing around with PowerCLI and Get - view in particular and I wanted to understand if there was a way to specify multiple conditions and a 'GOLD' between them make in filters.
    Something like...

    Notice-EEG - ViewType VirtualMachine-filter @{name = "ABC123" or snapshot! = "} # does not work

    I took a glance at the documentation and I was unable to find a solution, but maybe a more experienced writer can confirm this?
    Thank you!

    I'm afraid, this is not possible, that all expressions in the filter hash table must comply.

    So, indeed, all expressions are AND-ed together.

    You can make a combination of two Get - sight lines of course.

    But I admit that this solution is not elegant or optimal.

  • Regular Get-view filter expressions

    I have the following code:

    $vms = get-VM-location 'test '.

    for ($i = 0; $i - lt $vms. County; $i++)

    {

    $vmOS = get-View - ViewType 'VirtualMachine' - filter @{"Name" = $vms [$i] .name} - property @("Nom", "Config.GuestFullName") | Select-Object - property name, @{N = "ConfiguredOS"; E={$_. Config.GuestFullName}}

    $vmOS

    }

    $vms contains some virtual machines to a folder called 'test '. I have 2 virtual machines in the folder - 'test' and 'test2 '. When I run the code above, when the 'test' VM is put in the loop, she returned twice. Time for 'test', and 'test2 '. I'm looking for a regular expression that I can use to get the exact name of each virtual computer so that only 1 value is returned by $vmOS in each loop.

    The filter is a regular expression, you can use the indicators of positions (^ and $).

    Something like that

    $vms = get-VM-location 'test '.

    for ($i = 0; $i - lt $vms. County; $i++)

    {

    $vmOS = get-View - ViewType 'VirtualMachine' - filter @{"Name" = "^ $($vms[$i].name)$" ""}-property @("Nom","Config.GuestFullName") |

    Select-Object - property name, @{N = "ConfiguredOS"; E={$_. Config.GuestFullName}}

    $vmOS

    }

  • Get - VM to Get-View - viewtype VirtualMachine

    We want to replace our Get-VM with Get-View-viewtype VirtualMachine function, because it is a faster method.

    But for some reason, the output is not the same.

    You expect that they return both the same VirtualMachine object.

    Out with Get - VM:

    Name, PowerState, NUM CPUs, MemoryGB

    Out with Get-View - viewtype VirtualMachine:

    Capacity, Config, layout, LAyoutEx, storage,... all the VMware.Vim.VirtualMachine object.

    Our methods:

    $Hosts = get-VMsByLocation-site $Location

    $VMs = @)

    $Hosts | {ForEach}

    (A) $VMs += Get - VM $_

    (B) $VMs += Get-view -ViewType VirtualMachine - filter @{'Name' = $_}

    }

    https://www.VMware.com/support/developer/windowstoolkit/wintk40u1/HTML/get-VM.html

    https://communities.VMware.com/thread/474763

    https://www.VMware.com/support/developer/converter-SDK/conv50_apireference/Vim.virtualmachine.html

    https://pubs.VMware.com/vSphere-51/index.jsp#com.VMware.PowerCLI.cmdletref.doc/virtualmachine.html

    Hello, tendonsie-

    Yes, you are right: If you change the type of object that you are using, and then later call what's going used probably not work with .

    However, another part of the power of Get - view: you have direct access to a representation of the object "full" vSphere - the View .NET VirtualMachine object, in this case.  So, you do no need another call to get the CpuReservationMhz - you can get it directly from the object VirtualMachine who have already recovered you.  An example of include these goods in the output (based on the example I gave first):

    Get-View -ViewType VirtualMachine -Property Name,Runtime.PowerState,Config.Hardware,Config.CpuAllocation.Reservation | Select-Object Name,    @{n="PowerState"; e={$_.Runtime.PowerState}},    @{n="NumCPU"; e={$_.Config.Hardware.NumCPU}},    @{n="MemoryGB"; e={$_.Config.Hardware.MemoryMB / 1KB}},    @{n="CpuReservationMhz"; e={$_.Config.CpuAllocation.Reservation}}
    

    You see the additional calculated property, CpuReservationMhz, here.  Now you don't need even have call the Get-VMResourceConfiguration cmdlet.

    Thus, work comes to discover what are the properties of the View .NET object that you have recovered.  And this work is supported by the vSphere API documentation, a link that is available to VMware vSphere Web Services SDK Documentation.  How is that?

  • Get-View issue

    I try to get the specific host name and version number of the guests in a data center. I'm may be far, but here's what I use to date:

    $servers = get-Datacenter "my DataCenter | Get-Vmhost

    foreach ($server in $servers)

    {

    Get-view ViewType - HostSystem-Name, property Config.Product | Select Name, {$_.config.} Product.FullName} | Export-CSV P:\mypath

    }

    The issue I'm having is the for loop runs against the entire vCenter and not the variable so the output is all host names and the version numbers for the vCenter Server?  I checked that the $servers variable includes only hosts in the data center that I intended. What I'm missing here?

    Thank you

    You're doing a general Get-views against whole environment, which will return all the HostSystems.

    But there is indeed no need the loop ForEach and Get-View, you can access this property directly via the ExtensionData property.

    Something like that

    Get-Datacenter "my DataCenter | Get-Vmhost |

    Select Name, @{N = 'Full name'; E={$_. ExtensionData.Config.Product.FullName}} |

    Export CSV P:\mypath\report.csv - NoTypeInformation - UseCulture

  • Get-View for VMS in subfolders

    Hello community

    I need the list of all the virtual machines in a specific folder, including subfolders.

    In fact, I use the following script

    $vms = Get-Folder "VDI" | Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"}
    
    foreach($line in ($vms | Get-Random -Count 20) ) { 
        if($line.PowerState -eq "PoweredOff") {
            $line | Start-VM -RunAsync | Out-Null
        }
    }
    

    The script runs periodically, and it will take more than 30 seconds to over 2000 virtual machines I want to speed up with Get - view. I've already tried it, but unfortunately it does not list the virtual machines of the subfolders.

    Someone at - it an idea how to solve this problem?

    You can try like this

    $folderName = "VDI".

    $folder = get-View - ViewType property file-name - filter @{'Name' = $folderName} | Select MoRef - ExpandProperty

    Notice-EEG - ViewType VirtualMachine - SearchRoot $folder |

    Select name

  • Using Get - view instead of Get - VM for BusSharingMode from a virtual computer

    Yet again, another issue was with Get - view. I searched a lot of documentation, but still I don't get the logic how to find good properties that I need to use.

    In this case, I need to transfer this one:

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

    in:

    Notice-EEG - ViewType VirtualMachine-Property Name,Config.NameofthePropertyforBusSharingMode

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

    The closest thing 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 establish the connection.

    It is all documented in the VMware vSphere QAnywhere, but as the title suggests, this is a reference.

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

    Only no VMware book that explains a bit more on the vSphere API and objects is the book of Steve Jin, called VMware VI and vSphere SDK: management of VMware Infrastructure and vSphere

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

    In this specific question, you must know that all devices connected to a virtual computer is located in Config.Hardware.Device.

    It is a loop through the devices and extract the virtual SCSI controllers, also with bus physics active sharing.

    Once you have, it's simple extract properties.

    foreach ($vm in Get-View - ViewType VirtualMachine - Name property, 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}}

    }

    }

  • The use of Get - view instead of Get - VM for the advanced settings of a virtual computer

    I have a question in relation to the advanced settings of a virtual machine and using Get - view instead of Get - VM for this particular case:

    Get - VM * | Get-AdvancedSetting - name "scsi * sharing | Select the entity, Name, Value

    My idea is to use:

    Notice-EEG - ViewType VirtualMachine. Where {-not $_.} Config.Template} | Where {$_.} {Advanced.Setting - eq ' scsi * sharing "} | Select the entity, Name, Value

    but as far as I can see there is nothing for the advanced configuration of 'VirtualMachine' here: https://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FVirtualMachine.htm

    I also took a quick glance at https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.ConfigSpec.html , but I can't figure out how to use "extraConfig"in the script PowerCLI to extract this particular information for "Sharing of SCSI".»

    There is information how to use the API to add or change a computer virtual here .vmx file key advances: http://blogs.vmware.com/PowerCLI/2008/09/changing-vmx-fi.html but it is not clear to me how to use it just to extract information without changing what.

    Try like this

    foreach ($vm in (Get-View - ViewType VirtualMachine - property Name, Config.ExtraConfig - filter @{'Config.Template ' =' False'})) {}

    $vm. Config.ExtraConfig | where {$_.} Key - like "{scsi * sharing '} |"

    Select @{N = "VM"; E = {$vm. Name}},@{N='Template'; E = {$vm. Config.Template}}, Key, Value

    }

  • Get-view Config.Hardwar.Device network adapter key 4000 solve Type of device?

    I know Get-NetworkAdapter before someone proposes.

    Now when using Get-view I drill down on a single record to the NIC see example in the attached picture.

    I know that the device type is an e1000e I see not listed in the hardware configuration, so I'm sure that his code in a hash table.


    My best guess is that 4000 KEY = E1000E but I would like a complete list of all the buttons on the unit so that I can solve them in my scripts.

    Any help is welcome and appreciated thank you.

    The type of NETWORK adapter is the objecttype.

    The following will first list all the types of devices and then filter the E1000 map

    $vm = get-View - ViewType VirtualMachine-filter @{'name '=' MyVM'}

    $vm. Config.Hardware.Device | %{$_. GetType()}

    $vm. Config.Hardware.Device | Where {$_-is [VMware.Vim.VirtualE1000]}

  • Get-view do not show anything for some servers

    One of my colleagues has created a script to extract some VM PCI slot numbers the script seems simple like this and work for (most) servers.

    $ServerName = "Test01".

    $vmview = (get-View - ViewType VirtualMachine-filter @{"Name" = $ServerName}).config.hardware

    $AllSasControllers = $vmview. Device | Where {$_.} DeviceInfo.Summary - eq 'SAS LSI Logic'}

    foreach ($SasController to $AllSasControllers)

    {

    Write-Host "Pci slot number:" $SasController.SlotInfo.PciSlotNumber

    }

    It worked before, but since a few days on 3 virtual machines which are one of the 6 we want to check returns no results more. All 3 VM is connected to the same vCenter, while others are connected to another. Knowing this, we'll try another VM in the vCenter (defective)... .strange return these results...

    On a defective VM, I note that:

    $AllSasControllers is filled with the results

    But the slotinfo property is empty, so far I can only see this behavior on 3 virtual machines that worked fine before.

    We did a few add/remove disk shares a few weeks on all VM 6 on the two vCenters. (may be a clue)

    One has obtained clues where to look?

    After a restart of vCenter problem seems to have disappeared, requires that certain inconsistencies of data or something.

  • How to read the VM ProvisionedSpaceGB and UsedSpaceGB using get - view?

    Hello

    I would like to retrieve the properties of the VM ProvisionedSpaceGB and UsedSpaceGB using get - view and not get - vm.

    How do I do that?

    Thank you very much in advance!

    Kind regards

    André

    Hello, Andre-

    You can retrieve some properties of an object view VirtualMachine and then do some computed properties, such as:

    ## get the View object of this VM, with a choice few properties (faster), then select some info about the objectGet-View -ViewType VirtualMachine -Filter @{"Name" = "^myVM0$"} -Property Name,Summary.Storage |    Select Name,        @{n="ProvisionedSpaceGB"; e={($_.Summary.Storage.Committed + $_.Summary.Storage.Uncommitted) / 1GB}},        @{n="UsedSpaceGB"; e={$_.Summary.Storage.Committed / 1GB}}
    

    To just get these some properties in the call to Get-view is the smaller memory usage in the PowerShell session and much higher speed during the extraction of the View object (without specifying properties to retrieve, the cmdlet returns all properties). How does do for you?

  • total vm host running and availability with get-view

    Ways to find "on the virtual machine host total running" & availability with get-view, get-view gives the boot time, but no availability, we convert the startup time of availability?

    Hello, esxi1979-

    You can use something like:

    Get-View -ViewType HostSystem -Property name,Runtime.BootTime,Vm | Select name,    @{n="NumVM"; e={$_.Vm.Count}},    @{n="Uptime"; e={New-TimeSpan -Start $_.Runtime.BootTime}}
    

    The Uptime property is a Timespan object.  How does do for you?

Maybe you are looking for