KirkMunro / FormatPx

Better Formatting in PowerShell
Apache License 2.0
73 stars 5 forks source link

FormatPx 1.0.0.1 does not work with the Microsoft AD cmdlets #2

Closed KirkMunro closed 9 years ago

KirkMunro commented 9 years ago

Issue reported via email from a FormatPx user:

I'm using your great FormatPx module (added to my profile), but I'm getting some errors when working with the Active Directory module. Here is an example when running Get-ADDomain:

Out-Default : Unable to cast object of type 'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection' to type 'System.Collections.Generic.Stack`1[FormatPx.FormatRecord]'.

Any thoughts?

KirkMunro commented 9 years ago

It turns out that the AD cmdlets provide their own "special" treatment on the PSObject Properties collection. For normal cmdlets, if you use the Properties indexer to check if a property is there or not, the indexer will simply return null for properties that do not exist. For AD objects returned by the Microsoft AD module, the indexer will return a property with a null value for properties that do not exist. Since there is no way to distinguish between a real property that exists but has a null value and a property that does not exist, a different mechanism must be used to determine if properties exist when working with objects returned from the Microsoft AD module.

The new logic is to check the type of the member that is returned from the indexer. If the member type is PSAdaptedPropertyInfo, then an additional check must be performed, using Linq with the enumerator to see if the property actually exists in the collection. If the type is not PSAdaptedPropertyInfo, then the old type check logic works just fine.

This issue has been fixed and it is included in release 1.0.1.2 of FormatPx.

KirkMunro commented 9 years ago

FYI if you tried this yesterday...turns out I missed a step in the release processing, so this didn't get properly posted as a release on GitHub until today. But I also pushed out release 1.0.2.3 today, so just update your module to that version and you'll have this fix plus another one that was reported and fixed today as well.