Регулярные выражения power shell

Question: When defining the Expression value for custom properties, can we include either a try/catch or an if condition to handle errors and/or capture details of errors for logging purposes, without messing up the expression value itself?

Start-Transcript -Path 'c:\temp\log.txt' -Force
## List of AD user objects
$OU = "OU=Users,DC=company,DC=com"
$Users = Get-ADUser -LDAPFilter '(&(objectCategory=Person)(sAMAccountName=*))' -SearchBase $OU -Properties *
## this array will make sense later...
$missingMgrs = [System.Collections.ArrayList]@()
## Defined properties through splatting:
$ChosenProperties = @{ "Property" = @( # built-in attributes: 'Name', 'sAMAccountName', 'EmailAddress' # custom attributes below: @{ Label = "ManagerSAmAccountName" Expression = { Get-ADUser $_.Manager -Properties DisplayName |Select -Expand sAMAccountName } } )
}
$Users | Select-Object @ChosenProperties
Stop-Transcript

An excerpt from the transcript might look like this:

Name sAMAccountName EmailAddress ManagerSAmAccountName
---- -------------- ------------ ---------------------
Person One pone [email protected] managera
Person Two ptwo [email protected] managerb
>> TerminatingError(Get-ADUser): "Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again."
Person Three pthree [email protected]
>> TerminatingError(Get-ADUser): "Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again."
Person Four pfour [email protected]
Person Five pfive [email protected] managera
 Expression = { if ($($_.Manager.Length) -gt 0) { Get-ADUser $_.Manager -Properties DisplayName |Select -Expand sAMAccountName } else { $missingMgrs.Add("$($_.Name) is missing a manager.") } } 

and at the end, just before stopping transcript:

Write-Output $missingMgrs

However, that generates the results like this:

Name sAMAccountName EmailAddress ManagerSAmAccountName
---- -------------- ------------ ---------------------
Person One pone [email protected] managera
Person Two ptwo [email protected] managerb
>> TerminatingError(Get-ADUser): "Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again."
Person Three pthree [email protected] 0
>> TerminatingError(Get-ADUser): "Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again."
Person Four pfour [email protected] 1
Person Five pfive [email protected] managera
[...]
Person Three is missing a manager.
Person Four is missing a manager.

Back to the original question: Is there a way to write a custom property using an if/else so that the Expression’s value gets evaluated only when the if condition is met?