VMware Cloud Community
Fjorko
Contributor
Contributor
Jump to solution

Change Expression Output to something else

Hi all you very clever peeps !

How do I go about "swopping" the output of an expression so it substitutes the result into a more friendly answer :

Example:

@{N="Tools version  status";E={$_.ExtensionData.Guest.ToolsVersionStatus}}

The above will output an answer as : ToolsCurrent or something like that......

I want it to say "OK" ( my own friendly name )

I saw somewhere that you can replace the output with your own "answer" based on what that output is. I just do not know the syntax on how to do that

Any help is (as always) MUCH appreciated ! Sorry if I made absolutely no sense at all 🙂

Thanks all.

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can change the output in the scriptblock after "E=". For example:

Get-VM | Select-Object Name,@{Name="Tools version status";Expression={
  Switch -Expression ($_.ExtensionData.Guest.ToolsVersionStatus) {
    "guestToolsCurrent"      { "OK" }
    "guestToolsNeedUpgrade"  { "Not OK" }
    "guestToolsNotInstalled" { "Not OK" }
    "guestToolsUnmanaged"    { "Not OK" }
    ""                       { "Not OK" }
    default                  { "Not OK" }
  }
}}

Regards, Robert

Message was edited by: RvdNieuwendijk Added the default line to the Switch statement in the script.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
5 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can change the output in the scriptblock after "E=". For example:

Get-VM | Select-Object Name,@{Name="Tools version status";Expression={
  Switch -Expression ($_.ExtensionData.Guest.ToolsVersionStatus) {
    "guestToolsCurrent"      { "OK" }
    "guestToolsNeedUpgrade"  { "Not OK" }
    "guestToolsNotInstalled" { "Not OK" }
    "guestToolsUnmanaged"    { "Not OK" }
    ""                       { "Not OK" }
    default                  { "Not OK" }
  }
}}

Regards, Robert

Message was edited by: RvdNieuwendijk Added the default line to the Switch statement in the script.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
Fjorko
Contributor
Contributor
Jump to solution

Excellent. You people are geniuses !

How do you and LucD know all this stuff ?

For example - how do you know which properties and metods etc are available for a particular cmdlet ?

0 Kudos
DSTAVERT
Immortal
Immortal
Jump to solution

LucD read his own book.

-- David -- VMware Communities Moderator
0 Kudos
LucD
Leadership
Leadership
Jump to solution

For the cmdlet parameters you can consult the online reference.

To see what is in the objects returned by the cmdlets you can use the Get-Member cmdlet.

Get-VM MyVM | Get-Member

To see what is in the SDK objects, the once returned by Get-View or under the Extensiondata property, use the SDK online reference.


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

LOL :smileylaugh:

But since you mentioned it, you can find it here.


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

0 Kudos