ProxyAddress transforms logic
Describe the bug When querying users I see many errors from the Transform module in relation to the proxyAddresses attribute of contact objects.
To Reproduce Query the directory for mail objects that have a proxyAddresses value that contains something like this: SMTP:[email protected]; NOTES:John Amith1/Certifier@ICEB; X400:c=GB;a= ;p=IB;o=ICAO;s=Smith2;g=John;;
Note the empty/blank value at the end (between the two semi-colons)
Expected behavior For consideration - in my case there are three valid and one invalid entries in the proxyAddresses attribute. This is the account forest, Exchange existed in the resource forest. I don't think you should spew red errors to the console. I think an orange warning saying there's some rubbish in the proxyAddresses would be better. Take the values, handle the "error" (bad data really - I have no idea how we got into this state).
Or better yet, if there's more than one value in proxyAddresses why bother the user at all - just ignore/bin the empty value. Is it even worth outputting that there's rubbish there?
Environment (please complete the following information):
- OS: Windows Server 2022
- PowerShell version 5.1.20348.2849
- S.DS.P Module version 2.2.1
- The target AD environment is older though :) -- Server 2012 R2 AD DS, Exchange Server 8.3 and 15.0 don't complain when calling Get-MailUser or Get-Mailbox
Well, I looked at the code and: when invalid entry in multival attr --> transform logic throws and nothing returned in the attr. This is something I wanted to improve.
However, I did not want to just silently ignore invalid entries, not telling caller that something is wrong.
So I went the way of design intention of PowerShell engine and added better support for ErrorActionPreference in Find-LdapObject:
-
Stopjust throws on first invalid entry -
Continuewrites errors but continues processing -
SilentlyContinuejust swallows the errors and ignores invalid entries
What I'm still thinking about is the scope of ErrorActionPreference as I feel it might be too wide - setting to SilentlyContinue will just hide all errors encountered when querying, not only invalid attribute errors, which might not be suitable for every scenario.
Thoughts?
Anyway, experimental handling for proxyAddress transform is in 2.2.2-beta1 - please test / play with it
The error is verbose and very messy. With $ErrorActionPreference set to default 'Continue', e.g.
PS C:\Users\a-pawill> Find-LdapObject -LdapConnection $e1LDAPConn -searchBase "CN=Smith\, John,OU=NE Contacts,OU=Contacts,OU=ORG,DC=some,DC=domain,DC=co,DC=uk" -searchFilter "(objectClass=*)" -searchScope Base -PropertiesToLoad *
param(
[string[]]$Values
)
Process
{
foreach($Value in $Values)
{
try {
new-object ProxyAddress($Value)
}
catch {
Write-Error -ErrorRecord $_
}
}
}
Exception calling ".ctor" with "1" argument(s): "ProxyAddress: Provided value is not in correct format: [email protected]"
At C:\Users\a-pawill\Documents\WindowsPowerShell\Modules\S.DS.P\2.2.2\S.DS.P.psm1:1960 char:59
+ ... ttrName] = (& $transform.OnLoad -Values ($sr.Attributes[$attrName].Ge ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException
name : Smith, John
usncreated : 39710
textencodedoraddress : c=GB;a= ;p=IB;o=ICAO;s=Smith2;g=John;
…
I think it would be nice if there was just one line output that informed there was an error transforming the attribute in question, e.g. catch that and just write "ProxyAddress transformation: One or more provided values is not in correct format: [email protected]"