Fix win_user warning message (#24263)

Fix adds correct warning after deleting Windows User.
Also, adds modular function to get group

Fixes https://github.com/ansible/ansible/issues/24190

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/20333/head
Abhijeet Kasurde 8 years ago committed by Matt Davis
parent 63f8e6b68a
commit d8a9b9f347

@ -47,6 +47,11 @@ function Clear-UserFlag($user, $flag) {
$user.UserFlags = ($user.UserFlags[0] -BXOR $flag)
}
function Get-Group($grp) {
$adsi.Children | where { $_.SchemaClassName -eq 'Group' -and $_.Name -eq $grp }
return
}
########
$params = Parse-Args $args;
@ -163,7 +168,7 @@ If ($state -eq 'present') {
If (($groups_action -eq "remove") -or ($groups_action -eq "replace")) {
ForEach ($grp in $current_groups) {
If ((($groups_action -eq "remove") -and ($groups -contains $grp)) -or (($groups_action -eq "replace") -and ($groups -notcontains $grp))) {
$group_obj = $adsi.Children | where { $_.SchemaClassName -eq 'Group' -and $_.Name -eq $grp }
$group_obj = Get-Group $grp
If ($group_obj) {
$group_obj.Remove($user_obj.Path)
$result.changed = $true
@ -177,7 +182,7 @@ If ($state -eq 'present') {
If (($groups_action -eq "add") -or ($groups_action -eq "replace")) {
ForEach ($grp in $groups) {
If ($current_groups -notcontains $grp) {
$group_obj = $adsi.Children | where { $_.SchemaClassName -eq 'Group' -and $_.Name -eq $grp }
$group_obj = Get-Group $grp
If ($group_obj) {
$group_obj.Add($user_obj.Path)
$result.changed = $true
@ -201,7 +206,10 @@ ElseIf ($state -eq 'absent') {
$username = $user_obj.Name.Value
$adsi.delete("User", $user_obj.Name.Value)
$result.changed = $true
$result.msg = "User '$username' deleted successfully"
$user_obj = $null
} else {
$result.msg = "User '$username' was not found"
}
}
catch {
@ -235,7 +243,9 @@ try {
}
Else {
$result.name = $username
if ($state -eq 'query') {
$result.msg = "User '$username' was not found"
}
$result.state = "absent"
}
}

Loading…
Cancel
Save