-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect-vc.ps1
56 lines (49 loc) · 1.46 KB
/
connect-vc.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Connect and Disconnect to vCenter
<#
.SYNOPSIS
Connect or disconnect to/from vCenter server
.DESCRIPTION
Connect or disconnect to/from vCenter server
.PARAMETER Environment
Specify target VCenter environment
.INPUTS
None.
.OUTPUTS
None.
.EXAMPLE
Connect to vCenter in TierPoint:
PS> connect-vc.ps1 -VCServer fqdn.vcenter.local
.LINK
https://github.com/cloudtherapy/powercli/
#>
param(
[Switch] $Disconnect,
[String] $VCServer,
[String] $VCAdminUser="[email protected]"
)
# Ignore SSL warning for VCenter connection
Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
# Import PowerCLI Modules
Import-Module VMware.VimAutomation.Core -WarningAction SilentlyContinue
# Disconnect from VCServer if flag enabled
if ($Disconnect) {
Write-Output "Disconnected from VCenter ${VCServer}"
Disconnect-VIServer $VCServer -Confirm:$false
exit 1
}
# Connect to VCenter
if ($env:vcenter_pass) {
Write-Output "Connected to VCenter ${VCServer}"
Connect-VIServer $VCServer -User $VCAdminUser -Password $env:VCENTER_PASSWORD | Out-Null
} else {
Write-Output "ERROR: Please set environment variable vcenter_pass"
exit 1
}
# Verify VCenter Connection
if ($global:defaultviserver.Name -eq $VCServer) {
Write-Output "VCenter Connection Successful"
exit 0
} else {
Write-Output "ERROR: VCenter Connection Failed. Please validate connectivity and credentials"
exit 1
}