Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9315009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:16:43+00:00 2026-06-19T02:16:43+00:00

I’ve started rewriting my VMware daily report to use Get-View, rather than the related

  • 0

I’ve started rewriting my VMware daily report to use Get-View, rather than the related PowerCLI commands wherever possible, for performance reasons. One minor inconvenience with this is that the view objects returned often have many properties, many of which are objects themselves. Some properties are nested four or more levels deep.

So I’m trying to create a function which will output all properties of an object, along with the full path to that property. This could then be piped to Where-Object, to make finding specific properties easier. So to find a property relating to Host on a VMware.Vim.VirtualMachine object stored in $v, I would type something like:

Get-Properties -Object $v | ? {$_ -match "Host"}

And ideally, this would return a list of all nested properties of $v which contain the word “Host”.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:16:44+00:00Added an answer on June 19, 2026 at 2:16 am

    Perhaps there is an easier way to do this, but here’s what I came up with:

    function Get-Properties($Object, $MaxLevels="5", $PathName = "`$_", $Level=0)
    {
        <#
            .SYNOPSIS
            Returns a list of all properties of the input object
    
            .DESCRIPTION
            Recursively 
    
            .PARAMETER Object
            Mandatory - The object to list properties of
    
            .PARAMETER MaxLevels
            Specifies how many levels deep to list
    
            .PARAMETER PathName
            Specifies the path name to use as the root. If not specified, all properties will start with "."
    
            .PARAMETER Level
            Specifies which level the function is currently processing. Should not be used manually.
    
            .EXAMPLE
            $v = Get-View -ViewType VirtualMachine -Filter @{"Name" = "MyVM"}
            Get-Properties $v | ? {$_ -match "Host"}
    
            .NOTES
                FunctionName : 
                Created by   : KevinD
                Date Coded   : 02/19/2013 12:54:52
            .LINK
                http://stackoverflow.com/users/1298933/kevind
         #>
    
        if ($Level -eq 0) 
        { 
            $oldErrorPreference = $ErrorActionPreference
            $ErrorActionPreference = "SilentlyContinue"
        }
    
        #Initialize an array to store properties
        $props = @()
    
        # Get all properties of this level
        $rootProps = $Object | Get-Member -ErrorAction SilentlyContinue | Where-Object { $_.MemberType -match "Property"} 
    
        # Add all properties from this level to the array.
        $rootProps | ForEach-Object { $props += "$PathName.$($_.Name)" }
    
        # Make sure we're not exceeding the MaxLevels
        if ($Level -lt $MaxLevels)
        {
    
            # We don't care about the sub-properties of the following types:
            $typesToExclude = "System.Boolean", "System.String", "System.Int32", "System.Char"
    
            #Loop through the root properties
            $props += $rootProps | ForEach-Object {
    
                        #Base name of property
                        $propName = $_.Name;
    
                        #Object to process
                        $obj = $($Object.$propName)
    
                        # Get the type, and only recurse into it if it is not one of our excluded types
                        $type = ($obj.GetType()).ToString()
    
                        # Only recurse if it's not of a type in our list
                        if (!($typesToExclude.Contains($type) ) )
                        {
    
                            #Path to property
                            $childPathName = "$PathName.$propName"
    
                            # Make sure it's not null, then recurse, incrementing $Level                        
                            if ($obj -ne $null) 
                            {
                                Get-Properties -Object $obj -PathName $childPathName -Level ($Level + 1) -MaxLevels $MaxLevels }
                            }
                        }
        }
    
        if ($Level -eq 0) {$ErrorActionPreference = $oldErrorPreference}
        $props
    }
    

    When running it using the command

    Get-Properties -Object $v | ? {$_ -match "Host" }
    

    it returns

    $_.Capability.HostBasedReplicationSupported
    $_.Client.CertificateError.Method.DeclaringType.Assembly.HostContext
    $_.Client.CertificateError.Method.Module.Assembly.HostContext
    $_.Client.CertificateError.Method.ReflectedType.Assembly.HostContext
    $_.Client.CertificateError.Method.ReturnType.Assembly.HostContext
    $_.Client.ServiceContent.HostProfileManager
    $_.Client.ServiceContent.HostProfileManager
    $_.Client.ServiceContent.HostProfileManager.Type
    $_.Client.ServiceContent.HostProfileManager.Value
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Hardware.Device.Backing.HostPointingDevice
    $_.Config.Tools.SyncTimeWithHost
    $_.Guest.HostName
    $_.Guest.IpStack.DnsConfig.HostName
    $_.Guest.Net.DnsConfig.HostName
    $_.Runtime.Host
    $_.Runtime.Host
    $_.Runtime.Host.Type
    $_.Runtime.Host.Value
    $_.Summary.Guest.HostName
    $_.Summary.QuickStats.HostMemoryUsage
    $_.Summary.Runtime.Host
    $_.Summary.Runtime.Host
    $_.Summary.Runtime.Host.Type
    $_.Summary.Runtime.Host.Value
    

    Considering that the VMware.Vim.VirtualMachine object has 5087 nested properties, this is a much easier way to find what you’re looking for. Hopefully this can help someone else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.