-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidateESXiPassword.ps1
More file actions
31 lines (28 loc) · 1 KB
/
ValidateESXiPassword.ps1
File metadata and controls
31 lines (28 loc) · 1 KB
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
Function Validate-ESXiPassword {
[CmdletBinding()]
param (
[String]$HostName,
[String]$UserName,
[String]$CurrentPassword
)
$ErrorActionPreference = "Stop"
try {
$Connection = Connect-VIServer $HostName -User $UserName -Password $CurrentPassword
if ($Connection.isconnected) {
Write-Output "Success"
}
else {
Write-Output "Failed"
}
}
catch {
switch -wildcard ($error[0].Exception.ToString().ToLower()) {
"*incorrect user*" {
Write-Output "Incorrect username or password on host '$HostName'"; break
Disconnect-VIServer $HostName -Force -Confirm:$false
}
default { Write-Output "Error is: $($error[0].Exception.message)" }
}
}
}
Validate-ESXiPassword -HostName '[HostName]' -UserName '[UserName]' -CurrentPassword '[CurrentPassword]'