VMware Cloud Community
matkay521225
Contributor
Contributor
Jump to solution

Connect-VIServer fails to connect with passed credentials inside scripts but connects when manually typed

I have 4 vCenters.  The first 3 are all Windows vCenter installations.  I am able to connect to them via scripts with this method.

Connect-VIServer IP/DNS_Name -User administrator@vsphere.local -Password P@ssw0rd -Force

The 4th vCenter instance is a VCSA deployment and it will not accept this method in a script.  I've also tried the credential store method.

Two of the Windows vCenter instances are behind firewalls as is the VCSA instance I'm having issues with.  I've worked with our Cisco guru to insure that communication is not the issue.

I can consistently pass the above command manually via the cli and it connects to the VCSA every time, but when ran via a script, it consistently fails to connect to the VCSA.

VCSA Version

----------------

6.0.0 Update 3b build 5318203

PowerCLI Version

----------------

   VMware PowerCLI 6.5 Release 1 build 4624819

---------------

Component Versions

---------------

   VMware Cis Core PowerCLI Component 6.5 build 4624453

   VMware VimAutomation Core PowerCLI Component 6.5 build 4624450

   VMWare ImageBuilder PowerCLI Component 6.5 build 4561891

   VMWare AutoDeploy PowerCLI Component 6.5 build 4561891

   VMware Vds PowerCLI Component 6.5 build 4624695

   VMware Cloud PowerCLI Component 6.5 build 4624821

   VMware HA PowerCLI Component 6.0 build 4525225

   VMware HorizonView PowerCLI Component 7.0.2 build 4596620

   VMware Licensing PowerCLI Component 6.5 build 4624822

   VMware PCloud PowerCLI Component 6.5 build 4624825

   VMware Storage PowerCLI Component 6.5 build 4624820

   VMware vROps PowerCLI Component 6.5 build 4624824

   VMware vSphere Update Manager PowerCLI 6.5 build 4540462

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That seems to show that your Connect-VIServer does work.

If the script is having problems, it must be in another location.


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

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

Are there any 'special' characters in the password?

Did you try placing the password between single quotes?


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

0 Kudos
matkay521225
Contributor
Contributor
Jump to solution

It does have special characters.  I've tried single and double quotes.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you add a Start-Transcript and Stop-Transcript to the script?

That would perhaps show some more info.

Start-Transcript -Path C:\Temp\transcript.log

Connect-VIServer -Server MyVCSA -User MyUser -Password MyPswd -Verbose

Stop-Transcript


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

0 Kudos
matkay521225
Contributor
Contributor
Jump to solution

**********************

Windows PowerShell transcript start

Start time: 20180416170440

Username  : MyDomain\MyID

Machine   : myserver (Microsoft Windows NT 6.1.7601 Service Pack 1)

**********************

Transcript started, output file is C:\temp\transcript.log

  

Name                           Port  User                        

----                           ----  ----                        

vcsa                       443   VSPHERE.LOCAL\Administrator 

**********************

Windows PowerShell transcript end

End time: 20180416170444

**********************

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That seems to show that your Connect-VIServer does work.

If the script is having problems, it must be in another location.


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

0 Kudos
matkay521225
Contributor
Contributor
Jump to solution

The problem was in my connection verification code.

I changed this code to use the $global:defaultviserver and the verification is now working.

The key was my use of the Get-VIServer vs $global:defaultviserver in line 1.

New, working code:

$connection_result = $global:defaultviserver

if ($connection_result.Name -eq $vCenter) {

    Write-Host "Connected to: "$vCenter -ForegroundColor Green -BackgroundColor Black

}

In previous iterations of the script I was using the following code, which still works with my Windows vCenter servers.

Old code that doesn't work with VCSA.

$connection_result = Get-VIServer $vCenter

if ($connection_result.Name -eq $vCenter) {

    Write-Host "Connected to: "$vCenter -ForegroundColor Green -BackgroundColor Black

}

Thanks for the assistance LucD

0 Kudos
virtualtech_wor
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

We are hititng the same issue (passing credentials not working but manual working) on few vCenters.

All the other vCenters are connecting fine within the same script. 

Please advise. 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which format did you use for the account?

UPN (user@domain) or down-level (DOMAIN\user)?
Any output in the transcript log?


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

0 Kudos