# Catch block does not showing missing users

**URL:** <https://forums.powershell.org/t/catch-block-does-not-showing-missing-users/17888>\
**Category:** PowerShell Help\
**Created:** [November 7, 2021, 12:12am UTC](https://forums.powershell.org/t/catch-block-does-not-showing-missing-users/17888 "2021-11-07T00:12:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aman1313](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@aman1313](https://forums.powershell.org/u/aman1313)\
**Post date:** [November 7, 2021, 12:12am UTC](https://forums.powershell.org/t/catch-block-does-not-showing-missing-users/17888/1 "2021-11-07T00:12:41Z")

</div>

Hello,

I am trying to get users from AD by Importing CSV. Earlier I was able to see which users in CSV does not exist in AD by adding user’s fullname variable to catch block and catch block was showing full name of missing users. It stops working somehow. Can you please suggest why.

Thanks

```auto
 $UsersCSV = Import-CSV -path "C:\users\username\Downloads\FinalUserstoMove.csv"

ForEach($User in $UsersCSV){

Try{

    $FullName = $User."Display Name"
    $Username = $User."Username"

        Get-ADUser -Identity $Username | Select Name
        
    }

    Catch { Echo "$Fullname does not exist in AD"}

    Finally { }

} 

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 7, 2021, 12:33am UTC](https://forums.powershell.org/t/catch-block-does-not-showing-missing-users/17888/2 "2021-11-07T00:33:48Z")

</div>

The catch block only gets triggered when there’s a terminating error. If the cmdlet you run in the try block does not generate a terminating error by default you have to force it by using the parameter `-ErrorAction Stop`.

```auto
ForEach ($User in $UsersCSV) {
    Try {
        Get-ADUser -Identity $($User.UserName) -ErrorAction Stop | Select-Object -Property Name
    }
    Catch { 
        "'$($User."Display Name")' does not exist in AD" 
    }
}

```

---

<div class="post-metadata">

**Author:** ![aman1313](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@aman1313](https://forums.powershell.org/u/aman1313)\
**Post date:** [November 7, 2021, 12:39am UTC](https://forums.powershell.org/t/catch-block-does-not-showing-missing-users/17888/3 "2021-11-07T00:39:05Z")

</div>

Great, Thank you so much @Olaf much appreciated.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:20pm UTC](https://forums.powershell.org/t/catch-block-does-not-showing-missing-users/17888/4 "2024-05-16T20:20:36Z")

</div>


