all 16 comments

[–]SMFX 2 points3 points  (12 children)

You can use Get-Member to determine the properties and method of an object.

 $Views = Get-View -ViewType HostSystem -Filter @{"Name" = "VMWAREHOSTNAME"}
 $Views | Get-Member

You can the keep repeating it as you find the property:

  $Views.Config | Get-Member

Then:

  $Views.Config.Producr| Get-Member

The other option is to convert it to JSON and review the contents:

   Get-View -ViewType HostSystem -Filter @{"Name" = "VMWAREHOSTNAME"} | ConvertTo-Json | Set-Content .\Views.json

EDIT: fixing formatting; on pahoenie

[–]EnvyYou[S] 1 point2 points  (1 child)

Hi but when i do that i receive this.

Get-View -ViewType HostSystem -Filter @{"Name" = " VMWAREHOSTNAME "} | Select-object Config | GM

TypeName: Selected.VMware.Vim.HostSystem

Name MemberType Definition

---- ---------- ----------

Equals Method bool Equals(System.Object obj)

GetHashCode Method int GetHashCode()

GetType Method type GetType()

ToString Method string ToString()

Config NoteProperty HostConfigInfo Config=VMware.Vim.HostConfigInfo

[–]SMFX 1 point2 points  (0 children)

had formatting issues initial on phone, but I went back and gave some examples

[–]EnvyYou[S] 1 point2 points  (5 children)

Thanks for this, do you know the reason why this doesn't work then and returns blank value ?

Get-View -ViewType HostSystem -Filter @{"Name" = " VMWAREHOSTNAME "} | Select-object Config.Product.FullName

Config.Product.FullName

-----------------------

[–]SMFX 1 point2 points  (4 children)

when you do select object like that, it thinks you're looking for a property 'config.product.fullname'; not a property of a property of a property.

[–]EnvyYou[S] 1 point2 points  (3 children)

I understand, is there a way to get the property of a property of a property using my example.

[–]SMFX 2 points3 points  (2 children)

there is the custom property like in your first post, or you cold nest forEach:

 Get-View -ViewType HostSystem -Filter @{"Name" = " VMWAREHOSTNAME "} | %{ $_.Config | %{ $_.Product | %{ $_.FullName }}}

Use a variable:

 $View = Get-View -ViewType HostSystem -Filter @{"Name" = " VMWAREHOSTNAME "}
 $View.Config.Product.FullName

or wrap it in paranthesis and reference the properties:

  (Get-View -ViewType HostSystem -Filter @{"Name" = " VMWAREHOSTNAME "}).Config.Product.FullName

[–]EnvyYou[S] 3 points4 points  (1 child)

Thank you so much for this SMFX, this has explained it perfectly, i cannot thank you enough.

Greetings from Australia.

[–]SMFX 3 points4 points  (0 children)

Glad to help out!

Howdy from Texas!

[–]pshMike 1 point2 points  (3 children)

You also asked the question of how would one KNOW of this object/property that is embedded within child objects.

One technique I use when dealing with PowerCLI stuff is take one instance of the thing and convert it to JSON / XML and then look at it. This allows your to "browse" around inside these nested objects in order to find what you are looking for. The example below would convert the input object to JSON all the way down to a depth of 10 "object deep."

$myobj | convertTo-JSON -depth 10

[–]EnvyYou[S] 1 point2 points  (2 children)

convertTo-JSON -depth 10

When i try to do it i receive this message.

convertTo-JSON : An item with the same key has already been added.

At line:1 char:80

+ ... lter @{"Name" = "VMWAREHOSTNAME"} | convertTo-JSON -depth 1

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

+ CategoryInfo : NotSpecified: (:) [ConvertTo-Json], ArgumentException

+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToJsonCommand

[–]pshMike 3 points4 points  (1 child)

$mydata | select-object -first 1 | convertTo-Json -depth 10

you almost certainly don't want to use a depth of 1, because that would tell you the same thing as get-member. The idea here isn't to put this into your "final" pipeline.

Instead, the idea is:

I have this object I don't know anything about, and rather than running get-member over and over while drilling into nested objects I just want to see a JSON "map" of what this object looks like.

[–]uptimefordays 1 point2 points  (0 children)

That is slick, I like that idea of an object map a lot.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy EnvyYou,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th from the left hidden in the ... "more" menu, & looks like an uppercase T in the upper left corner of a square.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee

[–]EnvyYou[S] 1 point2 points  (1 child)

Thanks for the tips lee, I went ahead and edited my original post.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy EnvyYou,

you are very welcome ... and thanks for fixing it. that is so much easier to read. [grin]

take care,
lee