Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vCenter User #1

Closed
MeinhartEsrohr opened this issue Jun 15, 2021 · 2 comments
Closed

Add vCenter User #1

MeinhartEsrohr opened this issue Jun 15, 2021 · 2 comments

Comments

@MeinhartEsrohr
Copy link

Hello TheSleepyAdmins,
I have a question, is there a possibility to define a username and password when running the script ?
When I run the script, after a short time a window opens where I have to enter the credentials of the vCenter, so unfortunately my planned task does not work either.
We have three vCenter servers, on one it runs without problems, on the other two the login window pops up.

In Windows where I run the script I am logged in with my domain user who also has access to the vCenter servers.

Thank You!

@DonRWettr
Copy link

Hey there,

I've tried myself on the issue for a bit, and maybe it works by just passing along your credentials after saving them where you're running the script from:

$CredentialPath = $PSScriptRoot + "\Credentials\" + $env:USERNAME.clixml

if (Test-Path $PSScriptRoot\Credentials == False) {
    Write-Warning "Credentials folder does not exist, creating one..."
    New-Item -Path . -Name "Credentials" -ItemType "directory"
}

if (Test-Path -Path $CredentialPath == False) {
    Write-Warning "Credentials of current user not saved yet, prompting cmdlet..."
    Get-Credential | Export-Clixml -Path $CredentialPath
}

$Credentials = Import-clixml -Path $CredentialPath
Write-Host "Credentials of current user imported"

And then of course update the connect command accordingly:

$VCStatus = connect-VIServer $VCServer -Credential $Credentials -ErrorAction SilentlyContinue -ErrorVariable ErrorProcess;

You'll need to enter your credentials the first time you run it, but after that it should run on its own.
Again, can't verify if it works or not, since I don't have access to our vCenters right now, but maybe give it a go and see how it goes.

@TheSleepyAdmin
Copy link
Owner

Hi MeinhartEsrohr

Sorry didn't see this issue notification.

I have the script running against two different vCenter in linked mode and never seen the popup. I have seen the popup issue before when the certificate from vCenter is not trusted. Have you check this.

Also you could look at using New-VICredentialStoreItem to save credenital that can be a called later but it not something I can't add to the script as it different for each environment.

New-VICredentialStoreItem -User domain\username -Password Password -Host vc.domain.local -File C:\Temp\vicreds.xml

$logon = Get-ViCredentialStoreItem -File C:\Temp\vicreds.xml
Connect-VIServer -Server $logon.Host -User $logon.User -Password $logon.Password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants