PowerShell script exchange
Post Reply
dcd62
Enthusiast
Posts: 39
Liked: 4 times
Joined: Aug 20, 2014 1:00 pm
Contact:

Trying to query for a list of datastore clusters

Post by dcd62 »

I'm trying to query for a list of datastore clusters and return only the first name. It works ok if there are multiple names, but if only one DS cluster name is returned, it only get the first character.
I'm having trouble with this command $DestDatastore = $DRClusterMaxSize.Name[0]
I want to use the same command whether it's a single or multiple DSClusters

Example:
$DRClusterMaxSize = Get-VBRServer -Name $DRHost | Find-VBRViDatastoreCluster | Where {($_.Name -like $SASDSC)}

Then I tried this:
$DestDatastore = $DRClusterMaxSize.Name[0]
Multiple DSCluster names will return the first name - that's good
If only a single DSCluster name, I only get the first character of the name

Then I tried this:
$DestDatastore = $DRClusterMaxSize.Name
Multiple DSCluster names will return the both names - I only want the first
If only a single DSCluster name, I get the single name - that's good
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Trying to query for a list of datastore clusters

Post by veremin »

Can you describe your goal, please? If you want only to query vSphere resources, then, VMware PowerCLI might work better in this case? Thanks!
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Trying to query for a list of datastore clusters

Post by jhoughes »

You should be able to reformat your last line and get the desired result.

Try this instead:
$DestDatastore = $DRClusterMaxSize[0].Name
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests