Last active
August 7, 2020 17:14
-
-
Save jbowdre/4fcd886049937ec986edd1b5dc85102c to your computer and use it in GitHub Desktop.
Place this in the same directory as the default Initialize-PowerCLIEnvironment.ps1 to add functions to easily connect to multiple vCenters at once.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initialize-PowerCLIEnvironment_Custom.ps1 | |
# Place this alongside the default 'Initialize-PowerCLIEnvironment.ps1' script. | |
# Usage: | |
# 1) Call 'Update-Credentials' to create/update a ViCredentialStoreItem to securely store your username and password. | |
# 2) Call 'Connect-VCs' to open simultaneously connections to all the vCenters in your environment. | |
# 3) Do PowerCLI things. | |
# 4) Call 'Disconnect-VCs' to cleanly close all ViServer connections because housekeeping. | |
$vCenterList = @("vcenter1","vcenter2","vcenter3","vcenter4") | |
function Update-Credentials { | |
$newCredential = Get-Credential | |
Foreach ($vCenter in $vCenterList) { | |
New-ViCredentialStoreItem -Host $vCenter -User $newCredential.UserName -Password $newCredential.GetNetworkCredential().password | |
} | |
} | |
function Connect-VCs { | |
Foreach ($vCenter in $vCenterList) { | |
Connect-ViServer -Server $vCenter | |
} | |
} | |
function Disconnect-VCs { | |
Disconnect-Viserver -Server * -Force -Confirm:$false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment