Fix so it only deletes users that exist
This commit is contained in:
parent
6f87380248
commit
ce0909035b
1 changed files with 8 additions and 3 deletions
|
@ -86,17 +86,22 @@ if ($state -eq 'present') {
|
|||
Create-User $username $password
|
||||
}
|
||||
$result.changed = $true
|
||||
$user_obj = Get-User $username
|
||||
}
|
||||
catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
# Remove user
|
||||
try {
|
||||
Delete-User $bob
|
||||
$result.changed = $true
|
||||
if ($user_obj.GetType) {
|
||||
Delete-User $user_obj
|
||||
$result.changed = $true
|
||||
}
|
||||
else {
|
||||
Set-Attr $result "msg" "User '$username' was not found"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Fail-Json $result $_.Exception.Message
|
||||
|
|
Loading…
Reference in a new issue