# Getting the 'value' of get-vm without headers

**URL:** <https://forums.powershell.org/t/getting-the-value-of-get-vm-without-headers/15601>\
**Category:** PowerShell Help\
**Created:** [February 8, 2021, 6:59am UTC](https://forums.powershell.org/t/getting-the-value-of-get-vm-without-headers/15601 "2021-02-08T06:59:25Z")\
**Posts on this page:** 4\
**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, 6:59am UTC](https://forums.powershell.org/t/getting-the-value-of-get-vm-without-headers/15601/1 "2021-02-08T06:59:25Z")

</div>

Hi-

I have a code snippet below from inside a function:

```
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
write-host "Total number running VMs= " -NoNewline
$fcount
}
```

I want to display a list of VM’s on a host with formatted output which the first get-vm ($VCHostVMs) does **.** This is so the user can see what VM’s are on the host (User will be prompted later in the script to enter a VM name). Then I do a second get-vm to another variable ($VMvalue) so I can use

-expandproperty to strip the variable of it’s headers. Then I can do a compare on just the VM name to see if the user entered a VM that exists. I was just curious if there is a cleaner way to do this with just one get-vm? Don’t need to write the code for me, just give me some hints, tyvm.

&nbsp;

…ar

---

<div class="post-metadata">

**Author:** ![ferc](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ferc/32/2135_2.png) [@ferc](https://forums.powershell.org/u/ferc)\
**Post date:** [February 8, 2021, 7:07am UTC](https://forums.powershell.org/t/getting-the-value-of-get-vm-without-headers/15601/2 "2021-02-08T07:07:42Z")

</div>

```
Get-VM | Format-Table -HideTableHeaders -Property Name
```

Or remove ft at the end of line 2 and try this

```
$VCHostVMs.Name
```

Would any of these work? I’m not sure if I understand your request.

Also, if you already have the $VCHostVMs variable, you could simply reuse it to set the $VMvalue variable.

```
$script:VCHostVMs = get-vmhost -name $vchost | get-vm | Select Name,@{N='GuestOS';E={$_.GuestID}}
$script:VMvalue = $VCHostVMs | Select Name -ExpandProperty Name
```

&nbsp;

---

<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, 10:36am UTC](https://forums.powershell.org/t/getting-the-value-of-get-vm-without-headers/15601/3 "2021-02-08T10:36:14Z")

</div>

This is essentially what I used:

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

I was not sure about re-using the variable since it had other properties previously enumerated. I had to add the ‘out-default’ or else it would not output correctly. Thanks.

![]()

---

<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/getting-the-value-of-get-vm-without-headers/15601/4 "2024-05-16T20:27:53Z")

</div>


