Skip to content

Commit 9481bcd

Browse files
committed
Fix: fixed Update-VcenterRootPasswordExpiration to handle empty email string
Description: Fixed `Update-VcenterRootPasswordExpiration` to handle empty email string ref: #171 Signed-off-by: Sowjanya.V <[email protected]>
1 parent dc29486 commit 9481bcd

3 files changed

+44
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Bugfix:
1717
- Fix for missing account lockout policy data for SDDC Manager and vCenter Server. [GH-160](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/160)
1818
- Fix for `VMware.PowerCLI` module name not being mentioned in the required modules list of the manifest file. [GH-170](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/170)
1919
- Fix for `Test-VcfPasswordManagementPrereq` not working while multiple module versions were present. [GH-174](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/174)
20+
- Fix for `Update-VcenterRootPasswordExpiration` to handle empty email string. [GH-177](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/177)
2021

2122
## v1.7.1
2223

VMware.CloudFoundation.PasswordManagement.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = '.\VMware.CloudFoundation.PasswordManagement.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '1.7.2.1004'
14+
ModuleVersion = '1.7.2.1005'
1515

1616
# Supported PSEditions
1717
# CompatiblePSEditions = @()

VMware.CloudFoundation.PasswordManagement.psm1

+42-5
Original file line numberDiff line numberDiff line change
@@ -4604,14 +4604,13 @@ Function Update-VcenterRootPasswordExpiration {
46044604
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$user,
46054605
[Parameter (Mandatory = $false)] [ValidateNotNullOrEmpty()] [String]$pass,
46064606
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()] [String]$domain,
4607-
[Parameter (Mandatory = $false, ParameterSetName = 'expire')] [ValidateNotNullOrEmpty()] [String]$email,
4607+
[Parameter (Mandatory = $false, ParameterSetName = 'expire')] [String]$email,
46084608
[Parameter (Mandatory = $false, ParameterSetName = 'expire')] [ValidateNotNullOrEmpty()] [String]$maxDays,
46094609
[Parameter (Mandatory = $false, ParameterSetName = 'expire')] [ValidateNotNullOrEmpty()] [String]$warnDays,
46104610
[Parameter (Mandatory = $false, ParameterSetName = 'neverexpire')] [ValidateNotNullOrEmpty()] [Switch]$neverexpire
46114611
)
46124612

46134613
$pass = Get-Password -username $user -password $pass
4614-
46154614
Try {
46164615
if (Test-VCFConnection -server $server) {
46174616
if (Test-VCFAuthentication -server $server -user $user -pass $pass) {
@@ -4631,9 +4630,47 @@ Function Update-VcenterRootPasswordExpiration {
46314630
Write-Warning "Update Root Password Expiration Policy on vCenter Server ($($vcfVcenterDetails.fqdn)), already set: SKIPPED"
46324631
}
46334632
} else {
4634-
if ((Get-VcenterRootPasswordExpiration).max_days_between_password_change -ne $maxDays -or (Get-VcenterRootPasswordExpiration).email -ne $email -or (Get-VcenterRootPasswordExpiration).warn_days_before_password_expiration -ne $warnDays) {
4635-
Set-VcenterRootPasswordExpiration -email $email -maxDays $maxDays -warnDays $warnDays | Out-Null
4636-
if ((Get-VcenterRootPasswordExpiration).max_days_between_password_change -eq $maxDays -or (Get-VcenterRootPasswordExpiration).min_days_between_password_change -eq $minDays -or (Get-VcenterRootPasswordExpiration).warn_days_before_password_expiration -eq $warnDays) {
4633+
$vCenterRootPasswordExpirationSettings = Get-VcenterRootPasswordExpiration
4634+
$runUpdate = $true
4635+
$updateCommand = "Set-VcenterRootPasswordExpiration"
4636+
if ($maxDays) {
4637+
$updateCommand = $updateCommand + " -maxDays $maxDays"
4638+
if (($vCenterRootPasswordExpirationSettings).max_days_between_password_change -ne $maxDays) {
4639+
$runUpdate = $runUpdate -and $true
4640+
} else {
4641+
$runUpdate = $runUpdate -and $false
4642+
}
4643+
}
4644+
if ($warnDays) {
4645+
$updateCommand = $updateCommand + " -warnDays $warnDays"
4646+
if (($vCenterRootPasswordExpirationSettings).warn_days_before_password_expiration -ne $warnDays) {
4647+
$runUpdate = $runUpdate -and $true
4648+
} else {
4649+
$runUpdate = $runUpdate -and $false
4650+
}
4651+
}
4652+
if ($email) {
4653+
$updateCommand = $updateCommand + " -email $email"
4654+
if (($vCenterRootPasswordExpirationSettings).email -ne $email) {
4655+
$runUpdate = $runUpdate -and $true
4656+
} else {
4657+
$runUpdate = $runUpdate -and $false
4658+
}
4659+
}
4660+
if ($runUpdate) {
4661+
$condition = $true
4662+
Invoke-Expression $updateCommand | Out-Null
4663+
$vCenterRootPasswordExpirationSettings = Get-VcenterRootPasswordExpiration
4664+
if ($maxDays) {
4665+
$condition = $condition -and ($vCenterRootPasswordExpirationSettings).max_days_between_password_change -eq $maxDays
4666+
}
4667+
if ($warnDays) {
4668+
$condition = $condition -and ($vCenterRootPasswordExpirationSettings).warn_days_before_password_expiration -eq $warnDays
4669+
}
4670+
if ($email) {
4671+
$condition = $condition -and ($vCenterRootPasswordExpirationSettings).email -eq $email
4672+
}
4673+
if ($condition) {
46374674
Write-Output "Update Root Password Expiration Policy on vCenter Server ($($vcfVcenterDetails.fqdn)): SUCCESSFUL"
46384675
} else {
46394676
Write-Error "Update Root Password Expiration Policy on vCenter Server ($($vcfVcenterDetails.fqdn)): POST_VALIDATION_FAILED"

0 commit comments

Comments
 (0)