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

Tags: VMware

Similar Questions

  • 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?

  • How can I make reference to the parent object of a checkbox?

    I have a checkbox called P105_CBX, with 10 boxes. I have an onClick = "RunThisFunction (this) ' in the attributes of elements in HTML form for this object." When I click on one of the boxes, this function is triggered. An alert at the top of this function tells me that the argument passed to this function is something like P105_CBX_2, which indicates how box has been checked.

    I would LIKE to pass just the name parent of the object checkbox, P105_CBX, as the argument to this function, instead of the name of the box that was checked and I cannot quite understand how. I tried arguments such as this.container this.parentNode, this.parent, this.parents (), this.closest ('ul') and I've yet to find the magic word. After two hours of searching on Google, I'm turning to the experts.

    Thank you!

    Published by: Mark T. 17 March 2012 09:14

    Hello

    I couldn't reproduce your behavior. Maybe this is related to your prob? http://seanmonstar.com/post/707125202/parentNode-misbehavior-in-IE, but more likely, you have already seen it.

    In your code, you may also like to try the function $x_UpTill: http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/javascript_api.htm#CHDEGGGI

    function RunThisFunction (cbx) {}
    Alert ($x_UpTill(cbx,_'FIELDSET').id);
    }

  • 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?

  • get - view filtering

    The following code returns no resource pool yet I know that there are some

    $myhost = get-view viewtype - hostsystem-property name, Parent - filter @{'Name' = 'Blah'}

    $resourcepools = get-view - viewtype ResourcePool-property name, filter-owner @{'Owner' = $myhost. Parent}

    $resourcepools

    I also tried

    $myhost = get-view viewtype - hostsystem-property name, Parent - filter @{'Name' = 'Blah'}

    $resourcepools = get-view - viewtype ResourcePool-property name, filter-owner @{Owner.Value "= $myhost". ""} Parent.Value}

    $resourcepools

    Nothing helps.


    Anyone know why this is and how to do it?

    Kind regards


    Ryan

    It will work

    $resourcepools = get-view -viewtype ResourcePool -property Name, Owner -filter @{"Owner"=$myhost.Parent.Value}
    
  • MoRef filtered get - view

    Try to get resutlts an error

    PS > Get-View - ViewType property, Parent, MoRef hostsystem-name

    Get - view: 2011-02-08 08:46:35 Get-View

    Online: 1 character: 14

    + Get-view < < < < ViewType - hostsystem-name of the property, Parent, MoRef

    + CategoryInfo: NotSpecified: (:)) [Get-view], InvalidProperty)

    + FullyQualifiedErrorId: Client20_MoServiceImpl_GetNetInteropEntityView_ViError, VMware.VimAutomation.ViCore.Cmd

    ts.Commands.DotNetInterop.GetVIView

    I can still run and access.

    PS > (Get-View - ViewType hostsystem). MoRef

    Is there a way to specify this property which must be returned?

    Kind regards

    Ryan

    The command

    Get-view ViewType - hostsystem-name of the Parent property

    Returns an array if you have more than one host. This means that you must do something like:

    (Get-view ViewType - hostsystem-name of the Parent property) [0]. MoRef

    or

    $x = get - View - ViewType hostsystem-property name, Parent
    $x [0]. MoRef

    to retrieve the first host MoRef.

  • with Get-VIew-filter

    How can I search a host using its MoRef, code below does not work:

    Get-view viewtype - HostSystem-filter @ {"HostId"="host-139"}

    Luke,

    I was referring to the construction of the ManagedObjectReferen object.

    I wonder why you can not use the MoRef property. Maybe it's a bug.

    Can I use other moref properties, but NOT the property of MoRef

    The following example works:

    $v = get-view - ViewType virtualmachine-filter @{"runtime.host"="" ^ $host-2116 "}

    This wil return all virtual machines from the host-2116. The porperty runtime.host is of type ManagedObjectReference.

  • 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

  • Getting the data center of VirtualMachine with Get-View information

    Hello

    Y at - it a faster way to get the name of data using Get-View and the viewtype VirtualMachine Center.

    I found the following:

    Get-View -ViewType VirtualMachine -filter @{ "name" = "mtl1fsit02" } | Select-Object -Property Name,

    @{ Label = "GuestOSName"; Expression = { $_.summary.guest.guestfullname } },

    @{ Label = "Datacenter"; Expression = { (Get-view (Get-View (Get-view $_.parent).parent).Parent).name } }

    Thank you guys

    I think that the property calculated for the data center does not work in all situations.

    It assumes that your virtual machines are 3 levels down from the data center, which is not always the case.

    I personally use a loop, passing up through the parents, until he finds an object data center.

    something like that

    @{N = 'Center'; E = {}

    $parentObj = get-view $_. Parent

    While ($parentObj - isnot [VMware.Vim.Datacenter]({))

    $parentObj = get-view $parentObj.Parent

    }

    $parentObj.Name

    }

  • Folder is a virtual computer in the use of Get-View

    All, I run a script to collect information on the virtual machines in the environment, but have not been able to figure out how to get the file to in the virtual machine is.  I know I could use a get - vm | Select name, file etc. but at the time wherever I have add a get - vm statement, I'll add a TON of execution time of the script.

    I currently use it as my get-views command...

    Notice-EEG - ViewType VirtualMachine-Name property, Runtime.Host, Config.GuestFullName, Config.Annotation, Config.Hardware.NumCPU, Config.Hardware.MemoryMB, Guest.Disk, Config.Template, Guest.IpAddress | Sort-Object-property name. %{
    If ($_.) Config.Template - not $true) {}
    $row = "" | Select-Object Name, Notes, MemoryGB, host, CPU, OS, Cluster, IPAddress, DiskSpaceGB, UsedSpaceGB

    ....

    I know I'm just grabbing some properties, but I was not able to find the property that gives the name of the folder.

    To try to find the right one, I did

    $vm = get-View - ViewType VirtualMachine-filter @{"Name" ="VM_Name"}

    Then just walk through the $vm variable. (Property) etc.

    Anyone?

    In the VirtualMachine object, the Parent property contains the MoRef (pointer) to the object of the file.

    In order to

    Select Name,@{N="Folder; E = {Get-view $_.} Parent | Select name - ExpandProperty}}

  • Use get - view to get the host data center

    Hey guys,.

    I'm trying to shoot the host number of name and the version with get-view.

    I got to that, but I also want to get the data center that host belongs to.

    How can I get that advice please, don't have Googling has not helped a lot.

    Thank you

    RJ

    With the ExtensionData property we have access to the object VirtualMachine .

    Most of the managed objects vSphere has a property, called Parent, which points to the object that is connected to our object (the ' mother' in other words).

    The content of the Parent property is a MoRef (pointer). To get the real object, we use the cmdlet Get-view with this MoRef.

    We repeat this process in a while loop until the parent object is an object of data center .

    It's a bit like the structure of the tree in the vSphere Client.

    You start with the ESX (i) server and back up in the tree until you encounter a data center.

  • 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 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.

  • specify the name of the vm to get-view-filter of hash

    According to me, Miss me some eccentric or a convention with Powershell variables in a hash filter.

    My infrastructure includes these 3 VMs:
    UTIL
    otherUTIL
    anotherUTILserver

    I try to use something like the following to return only the virtual machine called UTIL. This returns all 3 VMs with UTIL in their name:

    $vm = 'UTIL '.

    Notice-EEG - ViewType VirtualMachine-filter @{"Name" = $vm} | Select - expand name

    Get line - see below eliminates anotherUTILserver but always returns otherUTIL with UTIL:

    Notice-EEG - ViewType VirtualMachine-filter @{'Name' = ' $$vm '} | Select - expand name

    With ' $vm$ ' I'm following comment by LucD here: http://rvdnieuwendijk.com/2011/09/12/how-to-use-VMware-vSphere-PowerCli-to-find-the-MAC-addresses-of-a-virtual-machine/#comment-22

    If necessary, I could use the GET more slow-but-more simple-vm, could add a foreach loop (my example is simplified), or might filter on an additional property in addition to the name. But I hope that there is a similar thing that will help you eliminate otherUTIL and filter return only UTIL, without adding complexity.

    Regular expression to the rescue: http://msdn.microsoft.com/library/az24scfc.aspx

    Notice-EEG - ViewType VirtualMachine-filter @{"Name" = "^ $vm$"} | Select - expand name

    Or without regex:

    $x = get-View - ViewType VirtualMachine-filter @{"Name" = $vm}

    $x | where {$_.name - eq $vm} | Select - expand name

  • The virtual computer name gets a snapshot object

    It must be a one esy, but I do not get the solution.

    I would get all the names of VM with at least a snapshot. And because the cmdlet get-snapshot does not work well in 4.0u1 I want to use it.

    I get all snapshots with:

     $rootsnap = Get-View -ViewType VirtualMachine |%{$_.Snapshot.RootSnapshotList} 

    Now, I would like to get the name of VM. I tried with:

      
    foreach ($snap in $rootsnap){
     $vmid = $snap.vm.type + "-" + $snap.vm.value
     get-vm -id $vmid
    }
    

    It works, because sometimes the $snap is empty.

    You can solve the guests with no snapshots with a cmdlet where clause.

    filter Get-SnapshotFast{
         $_.Name
         if($_.ChildSnapshotList){
              $_.ChildSnapShotList | Get-SnapshotFast
         }
    }
    
    Get-View -ViewType VirtualMachine | where {$_.Snapshot.RootSnapshotList} | %{
         Write-Host "VM name" $_.Name
         Write-Host "Snapshots`n" ($_.Snapshot.RootSnapshotList | Get-SnapshotFast)
    }
    

    Notice that I use a recursive function to browse to the snapshot.

    ____________

    Blog: LucD notes

    Twitter: lucd22

Maybe you are looking for

  • HP Jet 7 - updating the BIOS HP

    I have a few problems on my tablet. Windows does not load, he wants to update the BIOS, he wrote new BIOS image each time, but after writing and check the new BIOS image, he is himself reboot and do the same thing, windows does not load and I can't d

  • Should I downgrade ios 9.1 to 9.0.2

    Should I downgrade ios 9.1 to 9.0.2

  • Downgrade from Windows Vista to Windows XP Professional

    I have windows vista installed on my desktop hp-compaq computer and it started to become unstable, I was tired of troubleshooting and I decided to install windows xp professional because it doesn't have the ability to run windows 7 effectively. Whene

  • Windows vista family premium will not update

    Hi, I currently have a problem trying to update windows. I have windows vista Home premium sp2 and today Update icon just says that windows cannot check the updates. If I select "check for updates", the system seems to be verified but nothing happens

  • Photosmart Premium printer does not print

    Model number C310A E-all-in-one My documents all spots and will not print. I checked all the cords, etc. I turned off the printer and restarted. I turned off my computer and restarted. I have Windows 7. Help!