Hi,
I have a dashboard for our support people and they are going to do some things against vsphere so then the dashboard needs to connect to it. Well that’s not a problem but I only want the dashboard to connect to it once and not everytime someone accessing the dashboard.
Can I do it something like the module solution in the gui?
I have the PSU with a service account, maybe I can use the script function in PSU to connect?
Product: PowerShell Universal
Version: 1.4.6
You could connect outside the dashboard code, and then simply hook into the connection whenever you want to use it. For example, if I connect to two vCenters outside the dashboard code, I can take note of the session IDs like so:
$aHosts = @(
"vCenter1",
"vCenter2"
)
$creds = Get-Credential
$aConnection = Connect-VIServer -Server $aHosts -Credential $creds
$aConnection |
% {
Write-Host "$($_.Name): $($_.SessionId)"
}
Disconnect-VIServer -Server * -Confirm: $false
Running the above will populate the internal global:DefaultVIServers variable in PowerCLI. You can then later reconnect to these open sessions via their session IDs if you want to do something in that environment. While still using Connect-VIServer, you are simply connecting to the already-established session:
$vCenter = $global:DefaultVIServers | ? {$_.Name -match "vCenter2"}
Connect-VIServer -Server $vCenter.Name -Session $vCenter.SessionId
Get-VM | ? {$_.Name -match "CMO"} | Out-GridView #Simple test to prove connectivity.
The caveat to this, of course, will be security. You are going to want to use New-VICredentialStoreItem or some other method (even the vault in PSU) to ensure credentials are not being passed plain text.
How do I connect that once the dashboard are loaded? Just type in the code in the top of my dashboard? That’s what I don’t get where I write the code so it loads / connect at the same time as the dashboard.
For them who reads this later what I did was that I’m connecting to the vSphere and then save info to cache then disconnect.
I’m doing that with a script that are running every 2 min.
Then I’m just accessing that information from my dashboard.