diff --git a/changelogs/fragments/win_domain_user-make-query-try-catch-accurate.yml b/changelogs/fragments/win_domain_user-make-query-try-catch-accurate.yml new file mode 100644 index 00000000000..fec682d636f --- /dev/null +++ b/changelogs/fragments/win_domain_user-make-query-try-catch-accurate.yml @@ -0,0 +1,2 @@ +minor_changes: +- "win_domain_user - Make the query user try catch block more accurate for missing identity (https://github.com/ansible/ansible/issues/57719)" diff --git a/lib/ansible/modules/windows/win_domain_user.ps1 b/lib/ansible/modules/windows/win_domain_user.ps1 index 4584f0c7384..d1d2ddabe75 100644 --- a/lib/ansible/modules/windows/win_domain_user.ps1 +++ b/lib/ansible/modules/windows/win_domain_user.ps1 @@ -80,7 +80,7 @@ if ($null -ne $domain_server) { try { $user_obj = Get-ADUser -Identity $username -Properties * @extra_args } -catch { +catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] { $user_obj = $null }