1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Minor win_user fixes based on feedback.

This commit is contained in:
Chris Church 2014-11-24 00:43:55 -05:00 committed by Matt Clay
parent ab96ff8b6d
commit ff193241b1

View file

@ -150,8 +150,9 @@ If ($state -eq 'present') {
} }
ElseIf (($password -ne $null) -and ($update_password -eq 'always')) { ElseIf (($password -ne $null) -and ($update_password -eq 'always')) {
[void][system.reflection.assembly]::LoadWithPartialName('System.DirectoryServices.AccountManagement') [void][system.reflection.assembly]::LoadWithPartialName('System.DirectoryServices.AccountManagement')
$pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Machine', $env:COMPUTERNAME $host_name = [System.Net.Dns]::GetHostName()
# FIXME: ValidateCredentials fails if PasswordExpired == 1 $pc = New-Object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext 'Machine', $host_name
# ValidateCredentials fails if PasswordExpired == 1
If (!$pc.ValidateCredentials($username, $password)) { If (!$pc.ValidateCredentials($username, $password)) {
$user_obj.SetPassword($password) $user_obj.SetPassword($password)
$result.changed = $true $result.changed = $true
@ -195,6 +196,9 @@ If ($state -eq 'present') {
$user_obj.IsAccountLocked = $account_locked $user_obj.IsAccountLocked = $account_locked
$result.changed = $true $result.changed = $true
} }
If ($result.changed) {
$user_obj.SetInfo()
}
If ($groups.GetType) { If ($groups.GetType) {
[string[]]$current_groups = $user_obj.Groups() | ForEach { $_.GetType().InvokeMember("Name", "GetProperty", $null, $_, $null) } [string[]]$current_groups = $user_obj.Groups() | ForEach { $_.GetType().InvokeMember("Name", "GetProperty", $null, $_, $null) }
If (($groups_action -eq "remove") -or ($groups_action -eq "replace")) { If (($groups_action -eq "remove") -or ($groups_action -eq "replace")) {
@ -226,9 +230,6 @@ If ($state -eq 'present') {
} }
} }
} }
If ($result.changed) {
$user_obj.SetInfo()
}
} }
catch { catch {
Fail-Json $result $_.Exception.Message Fail-Json $result $_.Exception.Message