0

My first variables, is someting like: name OS version ---- ---- kead windows 2019 hanacockpit SLES12SP3 My second variables, is like

name GB ---- ---- kead 54.081582998856902122497558594 hanacockpit 384.20552698988467454910278320

As you can see the first column is name, as long as the second one has the same name,let's say kead,Join GB accordingly.

The final output is name OS version GB ---- ---- --- kead windows 2019 54.081582998856902122497558594 hanacockpit SLES12SP3 384.20552698988467454910278320

Anyway to do it?

Actually, variable1 and variable2 are from ESXI powercli.

# skip connection.

$all=Get-VM | 
   Get-View -Property @("Name", "config.GuestFullName") | 
   Select -Property Name,
       @{N="OS";E={$_.Config.GuestFullName}}

$space =get-vm | Select Name,@{N="disk-size";E= {@([math]::Round($_.ProvisionedSpaceGB / 1))}}


3
  • 1
    there are at least two merge or join modules in the powershell gallery site that seem able to handle that sort of thing. Commented Mar 19, 2020 at 10:25
  • $all | Join $space -On Name Commented Mar 19, 2020 at 12:11
  • Ah, thanks for you script. I tried it, works like a charm. Commented Mar 20, 2020 at 1:06

1 Answer 1

0

Maybe it's not quite what you're asking for, but you could just re-write your command into a one-liner...

Example:

   Get-VM | Select Name, @{N="OS";E={$_.ExtensionData.Config.GuestFullName}}, @{N="disk-size";E= {@([math]::Round($_.ProvisionedSpaceGB / 1))}}

If you're just looking for the join, my preference has generally been Join-Object: https://devblogs.microsoft.com/powershell/join-object/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.