I am getting an error -"Connect-VIServer : Invalid URI: The hostname could not be parsed." when i try to connect from Powershell script. however if i try the command from powecli promt it works. Can someone hlep here?
Are you sure your .ps1 file is saved as a UniCode file?
Or are there any "special" characters in the hostname?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
there are no special characters in the hostname .. i tried with IP as well .. only with Script its giving me an issue.. on powercli command prompt it works fine...
appreciate your help
Thanks
Rohit
Can you try adding the Verbose switch on the Connect-VIServer cmdlet?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hopefully by this time you have figured it out but still sharing my experience
Please make sure you don't have any space left after the host name in a txt file or csv file. I have had the same problem and it was found that after the VC name there was plenty of blank space. when i removed that then it worked well.
Hi,
Can anyone help? can I call vc name, username, password from an excel file? is my approach correct?
PS C:\> $ExcelFile = "C:\Temp\Configure_vCenter\Version_2.0\vSphereDetails.xlsx"
$vCenter = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 1 -EndColumn 1
$vCUser = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 2 -EndColumn 2
$vCCreds = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 3 -EndColumn 3
Connect-VIServer -Server $vCenter -User $vCUser -Password $vCCreds
Connect-VIServer : Invalid URI: The hostname could not be parsed.
At line:5 char:1
+ Connect-VIServer -Server $vCenter -User $vCUser -Password $vCCreds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-VIServer], UriFormatException
+ FullyQualifiedErrorId : System.UriFormatException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer
PS C:\> $vCenter
vCenter Name
------------
mylabvcsa.mylabnet.local
PS C:\> $vCUser
Username
--------
vcadmin@mylabnet.local
PS C:\> $vCCreds
Password
------------
VMware1!
Did you check the Length of the string in the $vCenter variable?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the prompt response LucD!
The error remain same even if I reduce the length of $vCenter variable
PS C:\> $ExcelFile = "C:\Temp\Configure_vCenter\Version_2.0\vSphereDetails.xlsx"
$vCenter = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 1 -EndColumn 1
$vCUser = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 2 -EndColumn 2
$vCCreds = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 3 -EndColumn 3
Connect-VIServer -Server $vCenter -User $vCUser -Password $vCCreds
Connect-VIServer : Invalid URI: The hostname could not be parsed.
At line:5 char:1
+ Connect-VIServer -Server $vCenter -User $vCUser -Password $vCCreds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-VIServer], UriFormatException
+ FullyQualifiedErrorId : System.UriFormatException,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer
PS C:\> $vCenter
vCenter Name
------------
mylabvcsa
That is not what I mean.
When you do $vCenter.Length does that number correspond with the number of characters that are supposed to be in the hostname of the VCSA?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The output is null.
PS C:\> $vCenter = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 1 -EndColumn 1
PS C:\> $vCenter
vCenter Name
------------
mylabvcsa.mylabnet.local
PS C:\> $vCenter.length
PS C:\>
PS C:\>
If I define the variable manually (not fetching from excel), it's reporting the length of the variable.
PS C:\> $vCenter = "mylabvcsa.mylabnet.local"
PS C:\> $vCenter
mylabvcsa.mylabnet.local
PS C:\> $vCenter.length
24
PS C:\>
PS C:\>
It looks as if you have to refer to the name with $vCenter.'vCenter Name' instead of just $vCenter.
You probably have to check the user and password variables as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's fantastic !!! You're a GURU 🙏
PS C:\> $vCenter = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 1 -EndColumn 1
PS C:\> $vCenter.'vCenter Name'
mylabvcsa.mylabnet.local
PS C:\> $vCUser = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 2 -EndColumn 2
PS C:\> $vCCreds = Import-Excel $ExcelFile -WorksheetName vCenter -StartRow 1 -EndRow 2 -StartColumn 3 -EndColumn 3
PS C:\> Connect-VIServer -Server $vCenter.'vCenter Name' -User $vCUser.'Username' -Password $vCCreds.'Password'
Name Port User
---- ---- ----
mylabvcsa.mylabnet.local 443 MYLABNET.LOCAL\vcadmin