I am coding something using ActiveDirectory commandlet Get-AdUser.
$tempUser = Get-ADUser -Identity "Tataboutlamine" -Property * -ErrorAction Stop
If the user's identity cannot be found in AD, the reference tells us that the Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException will be raised. When I try to try-->catch the specific exception, PowerShell Studio 2022 reports that :
At line:590 char:10 Type [ActiveDirectory.Management.ADIdentityNotFoundException] introuvable.
Here a code sample :
- try
- {
- $tempUser = Get-ADUser -Identity $strUserName -Property * -ErrorAction Stop
- $this.setAddress(($tempUser).StreetAddress)
- $this.setCity(($tempUser).L)
- $this.setPostalCode(($tempUser).PostalCode)
- $this.setProvince(($tempUser).st)
- $this.setCountry(($tempUser).Co)
- $this.setOffice(($tempUser).physicalDeliveryOfficeName)
- $this.setDepartment(($tempUser).Department)
- $this.setEmployeeType(($tempUser).EmployeeType)
- $this.setDescription(($tempUser).Description)
- $this.setOfficePhone(($tempUser).TelephoneNumber)
- $this.setCompany(($tempUser).Company)
- $this.setTitle(($tempUser).Title)
- $tempUser = $null
- }
- Catch [ActiveDirectory.Management.ADIdentityNotFoundException]
- {
- throw [ADUserAccountException]::new("$(GetText('msgSourceAccountNotFound'))", $strUserName)
- }
It is working when I submit this code into Powershell ISE.
Thanks !