Skip to content

Instantly share code, notes, and snippets.

@matthewoestreich
Created March 29, 2019 14:12
Show Gist options
  • Save matthewoestreich/202f54aa763fece8774f23d0c855cce9 to your computer and use it in GitHub Desktop.
Save matthewoestreich/202f54aa763fece8774f23d0c855cce9 to your computer and use it in GitHub Desktop.
function Get-Connected {
try {
if(-not (Get-Module VMware.PowerCLI)){
Write-Host "You need the PowerCLI module!" -f yellow
Write-Host "We will install it for you, please click 'Yes To All' if prompted!" -f green
Install-Module VMware.PowerCLI -Cofirm:$false -Force
}
if(-not (Get-Module CredentialManager)){
Write-Host "You need the Credential Manager module!" -f yellow
Write-Host "We will install it for you, please click 'Yes To All' if prompted!" -f green
Install-Module -Name CredentialManager -Cofirm:$false -Force
}
Import-Module VMware.PowerCLI
Import-Module CredentialManager
$VumVmHostUpgradePath = Read-Host "Please enter the location where you saved the 'VUMvmhostUpgrad.psm1' module:"
Import-Module -Path $VUMvmhostUpgradePath
$TargetESXHost = Read-Host "Please enter target ESX Host you would like to connect to:"
if(-not (Get-StoredCredential -Target $TargetESXHost) {
$UserCreds = Get-Credential -Message "Please enter VCENTER credentials!!!"
New-StoredCredential -Credential $UserCreds -Target $TargetESXHost -Persist LocalMachine
}
} catch {
Write-Error "Something went wrong! Full Error: `r`n`r`n$($_)"
}
}
Get-Connected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment