Skip to content

Commit 597c8be

Browse files
authored
fix: update Update-VcenterRootPasswordExpiration empty email handling (vmware#177)
Fixed `Update-VcenterRootPasswordExpiration` to handle empty email string. Ref: vmware#171 Signed-off-by: Sowjanya.V <[email protected]>
1 parent 4a45341 commit 597c8be

File tree

2 files changed

+48
-10
lines changed

2 files changed

+48
-10
lines changed

Diff for: CHANGELOG.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ Breaking Change:
1010

1111
Enhancement:
1212

13-
- Added 5.1.1.0 to `Get-PasswordPolicyDefault` and `Get-PasswordPolicyConfig` to support VMware Cloud Foundation 5.1.1. [GH-164](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/164)
13+
- Added 5.1.1.0 to `Get-PasswordPolicyDefault` and `Get-PasswordPolicyConfig` to support VMware Cloud Foundation 5.1.1. [GH-164](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/164)
1414
- Enhanced `Get-PasswordPolicyDefault` to show summary in easily readable format. [GH-178](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/178)
1515

1616
Bugfix:
1717

1818
- Fixed 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)
19-
- Fixed `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)
19+
- Fixed `VMware.PowerCLI` module name not being added 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)
2020
- Fixed `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)
21+
- Fixed `Update-VcenterRootPasswordExpiration` to handle empty email string. [GH-177](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/177)
2122

2223
Chore:
2324

@@ -61,7 +62,7 @@ Bugfix:
6162

6263
Enhancement:
6364

64-
- Added 5.1.0.0 to `Get-PasswordPolicyDefault` and `Get-PasswordPolicyConfig` to support VMware Cloud Foundation 5.1. [GH-130](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/130)
65+
- Added 5.1.0.0 to `Get-PasswordPolicyDefault` and `Get-PasswordPolicyConfig` to support VMware Cloud Foundation 5.1. [GH-130](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/130)
6566
- Updated `Update-SddcManagerPasswordComplexity`, `Update-SddcManagerAccountLockout`, and `Update-vCenterAccountLockout` cmdlet to support VMware Cloud Foundation 5.1 by addressing changes in Photon OS 4 for vCenter Server 8.0.2 and SDDC Manager 5.1. [GH-130](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/130)
6667

6768
Documentation:
@@ -125,7 +126,7 @@ Bugfix:
125126
- Updated `Get-PasswordPolicyDefault` to include support for VMware Cloud Foundation 4.5.2. [GH-91](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/91)
126127
- Updated `Get-PasswordPolicyConfig` to include support for VMware Cloud Foundation 4.5.2. [GH-91](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/91)
127128
- Updated `Get-PasswordPolicyDefault` to include support for VMware Cloud Foundation 4.5.0. [GH-71](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/71)
128-
- Updated `Get-PasswordPolicyConfig` to include support for VMware Cloud Foundation 4.5.0. [GH-71](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/71)
129+
- Updated `Get-PasswordPolicyConfig` to include support for VMware Cloud Foundation 4.5.0. [GH-71](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/71)
129130
- Updated `Invoke-PasswordPolicyManager` to address version support updates and JSON file depth handling. [GH-71](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/71)
130131
- Updated `Request-NsxtEdgePasswordExpiration` to pass the `-transportNodeId` parameter to `Get-NsxtApplianceUser` to retrieve the NSX Edge node ID. [GH-76](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/76)
131132
- Updated `Update-NsxtEdgePasswordExpiration` to pass the `-transportNodeId` parameter to `Get-NsxtApplianceUser` and `Set-NsxtApplianceUserExpirationPolicy` to retrieve the NSX Edge node ID. [GH-76](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/76)
@@ -214,7 +215,7 @@ Bugfix:
214215
- Fixed drift option error for `Publish-VcenterLocalAccountLockout`. [GH-34](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/34)
215216
- Fixed drift option error for `Publish-VcenterLocalPasswordExpiration`. [GH-34](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/34)
216217
- Fixed drift option error for `Publish-VcenterLocalPasswordComplexity`. [GH-34](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/34)
217-
- Handled empty email string values and "0" value for WSADirectory feilds coming from JSON file `Test-PasswordPolicyConfig`. [GH-36](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/36)
218+
- Handled empty email string values and "0" value for WSADirectory feilds coming from JSON file `Test-PasswordPolicyConfig`. [GH-36](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/36)
218219
- Corrected Description in `Start-PasswordPolicyConfig`. [GH-36](https://github.com/vmware/powershell-module-for-vmware-cloud-foundation-password-management/pull/36)
219220

220221
Enhancement:

Diff for: 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)