VMware Cloud Community
adamjg
Hot Shot
Hot Shot
Jump to solution

Get-Cluster outputting blank list?

Hopefully this should be easy, but it has me completely baffled. I'm putting together a script that will ask a number of questions and deploy a VM based on the answers.  One of my sections of code is an "other" section that instead of choosing from a menu, the person running the script can manually enter things such as Cluster name, Resource Pool name and Datastore.  I prompt for Cluster name, then run a Get-Cluster command to output a list of Resource Pools, prompt the user to pick a Pool, then run a command to list the datastores available on the hosts within a cluster.  This is where it gets weird.  If I run these commands manually in a Powershell/CLI window, they work fine, but when I run it in a .ps1 script, the datastore list outputs blank lines in place of where the list should be.  Here's a very stripped down portion of this code:

$ClusterInput = Read-Host "Enter the VMware cluster name"

Connect-VIServer vcenter | Out-Null

Get-Cluster $ClusterInput | Get-ResourcePool | Select @{N="Resource Pool";E={$_.Name}} | Where-Object {$_.'Resource Pool' -ne 'Resources'}

$ResourcePool = Read-Host "Enter the name of a Resource Pool listed above to place the virtual machine"

$myCluster = Get-Cluster -Name $ClusterInput | Get-ResourcePool $ResourcePool

Write-Host "Retrieving a list of Datatores in cluster $ClusterInput..."

Get-Cluster $ClusterInput | Get-VMHost | Get-Datastore | Sort Name

The last line, 07, is what shows the blank lines.  Line 03 outputs just fine, and is basically the same thing.

I can assign a variable for line 07 and then run through a loop to output it, but the format isn't as nice as what the one liner should be able to do on its own

Any ideas?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try changing that last line to

Get-Cluster $ClusterInput | Get-VMHost | Get-Datastore | Sort Name | Out-Host


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try changing that last line to

Get-Cluster $ClusterInput | Get-VMHost | Get-Datastore | Sort Name | Out-Host


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

0 Kudos
adamjg
Hot Shot
Hot Shot
Jump to solution

Yup that did it!  I suppose that's what happens when my source of powershell info has been google Smiley Happy  Thanks!

0 Kudos