# Just getting the 'value' of get-vm without headers

**URL:** <https://forums.powershell.org/t/just-getting-the-value-of-get-vm-without-headers/15600>\
**Category:** PowerShell Help\
**Created:** [February 8, 2021, 5:27am UTC](https://forums.powershell.org/t/just-getting-the-value-of-get-vm-without-headers/15600 "2021-02-08T05:27:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![araczek](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@araczek](https://forums.powershell.org/u/araczek)\
**Post date:** [February 8, 2021, 5:27am UTC](https://forums.powershell.org/t/just-getting-the-value-of-get-vm-without-headers/15600/1 "2021-02-08T05:27:04Z")

</div>

I am getting the VM’s from an ESXi host and displaying them, formatted . Then I want to search that list with a user entered VM and verify against that list that the VM entered exists. I have this (note this is only partial code of the script):

```
Write-Host "Displaying VM's on host: " $vchost -ForegroundColor Green
$script:VCHostVMs = get-vmhost -name $vchost | get-vm | Select Name,@{N='GuestOS';E={$_.GuestID}} | ft
$script:VMvalue = get-vmhost -name $vchost | get-vm | Select Name -ExpandProperty Name
$cnt = [pscustomobject]@{ VMCount = (Get-VMHost -Name $vchost | Get-VM).Count }
$fcount = $cnt.vmcount
```

The only way I could figure to show a formatted output so the user could see and then enter an existing name to run a test against a list of vm’s was do get-vm a second time with a second variable and Name -expandproperty. Is there a cleaner way? Not asking you to write my code, just asking if there is a better way? It’s the “cake and eat it too” scenario.

TIA.

&nbsp;

…Ar  
write-host "Total number running VMs= " -NoNewline  
$fcount

&nbsp;

&nbsp;

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [February 25, 2021, 9:54pm UTC](https://forums.powershell.org/t/just-getting-the-value-of-get-vm-without-headers/15600/2 "2021-02-25T21:54:55Z")

</div>

You actually call Get-VMHost | Get-VM 3 times. If you capture all possible output in one go, then you can pull what you want out of it without repeating the calls.

```auto
Write-Host "Displaying VM's on host: " $vchost -ForegroundColor Green

$GetAllOutputInOneCommand = get-vmhost -name $vchost | get-vm | Select-Object -Property *

$script:VCHostVMs = $GetAllOutputInOneCommand | Select-Object Name,@{N='GuestOS';E={$_.GuestID}}
$script:VMvalue = $GetAllOutputInOneCommand | Select-Object -ExpandProperty Name
$cnt = [pscustomobject]@{ VMCount = $GetAllOutputInOneCommand.Count }
$fcount = $cnt.vmcount

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:27pm UTC](https://forums.powershell.org/t/just-getting-the-value-of-get-vm-without-headers/15600/3 "2024-05-16T20:27:48Z")

</div>


