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

Trying to query for a list of datastore clusters

Post by dcd62 » Jul 06, 2019 6:55 pm

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: 16666
Liked: 1390 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 » Jul 07, 2019 1:55 pm

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 Software
Posts: 91
Liked: 21 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Trying to query for a list of datastore clusters

Post by jhoughes » Jul 07, 2019 5:07 pm

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 | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests