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.
…Ar
write-host "Total number running VMs= " -NoNewline
$fcount