VMware Cloud Community
oz2edri
Contributor
Contributor
Jump to solution

Error "Connect-VIServer : Invalid URI: The hostname could not be parsed" when using a variable

I'm getting the error "Connect-VIServer : Invalid URI: The hostname could not be parsed" when I try to connect to vCenter servers whose names are defined in a variable.

However, when I list them directly in the command I'm able to connect to them, and there's no error.

oz2edri_0-1617030618136.png

 

I'd love to know what am I doing wrong.

Thanks

 

Labels (4)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Your variable is interpreted as 1 string, not as an array of strings.
This should work

$vc = 'vc1','vc2'
Connect-VIServer -Server $vc


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

Your variable is interpreted as 1 string, not as an array of strings.
This should work

$vc = 'vc1','vc2'
Connect-VIServer -Server $vc


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

oz2edri
Contributor
Contributor
Jump to solution

And indeed it works.

oz2edri_0-1617031067430.png

Thanks a lot for the quick response and for the great explanation.

0 Kudos