I have a question but I want to state my understanding/observations in case I’m missing something…
I’m trying to write a function that gets a particular set of properties from AD. Some of the properties don’t exist on all objects.
When using Get-ADUser, requesting a property that doesn’t exist causes an error which prevents a result from being returned, regardless of what the error action preference is set to. As a way around this, I’m using a preference of Stop and am using the error code to pull out attributes from the ArrayList until I get a proper set of attributes.
Looking at DirectorySearcher, you can seemingly give it any number of properties to retrieve. Instead of erroring or anything, it instead only returns the properties it found on the object.
This is basically perfect for what I want, but I’m noticing that DirectorySearcher doesn’t seem to have the same number of properties available to query from. For example, I can query for the IPv4Address property with Get-ADComputer but that’s not returned by DirectorySearcher.
The default for DirectorySearcher is to grab all properties, and I couldn’t find anything analogous.
The question is:
Is there a way to have Get-AD* function more akin to DirectorySearcher? Maybe by like returning null for properties not found or just stripping them from the query?
Also, for my knowledge: what about DirectorySearcher causes it to have less properties than what one can get from the ActiveDirectory.Management module