-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommonFunctions.ps1
57 lines (50 loc) · 1.86 KB
/
CommonFunctions.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
57
##
###########################################################################################################
## Common Functions ##
###########################################################################################################
##
Function Write-Log {
param(
[Parameter(Mandatory=$true)]
[string]$Message,
[switch]$Warning = $false
)
$Timestamp = Get-Date -Format "MM-dd-yyyy hh:mm:ss"
Write-Host -NoNewline -ForegroundColor White "[$Timestamp]"
if($Warning){
Write-Host -ForegroundColor Yellow " WARNING: $Message"
} else {
Write-Host -ForegroundColor Green " $Message"
}
$LogMessage = "[$Timestamp] $Message"
$LogMessage | Out-File -Append -LiteralPath $VerboseLogFile
}
function Get-VCSAConnection {
param(
[string]$vcsaName,
[string]$vcsaUser,
[string]$vcsaPassword
)
$existingConnection = $global:DefaultVIServers | where-object -Property Name -eq -Value $vcsaName
if($existingConnection -ne $null) {
return $existingConnection;
} else {
$connection = Connect-VIServer -Server $vcsaName -User $vcsaUser -Password $vcsaPassword -WarningAction SilentlyContinue;
return $connection;
}
}
function Close-VCSAConnection {
param(
[string]$vcsaName
)
if($vcsaName.Length -le 0) {
Disconnect-VIServer -Server $Global:DefaultVIServers -Confirm:$false
} else {
$existingConnection = $global:DefaultVIServers | where-object -Property Name -eq -Value $vcsaName
if($existingConnection -ne $null) {
Disconnect-VIServer -Server $existingConnection -Confirm:$false;
} else {
Write-Log -Message "Could not find an existing connection named $($vcsaName)" -Warning
}
}
}