I have the following code:
$Users = Get-ADUser -Server $Domain -ResultPageSize 500000 -Filter * -Properties *, "msDS-UserPasswordExpiryTimeComputed" |
Select-Object * -ExcludeProperty *Certificate, PropertyNames,
*Properties, PropertyCount, Certificates, nTSecurityDescriptor
foreach ($U in $Users) {
$($U.PSobject.Properties.Name).Count
}
When you check count of properties for each object, it will be different. In the case of my test domain, this ranges from 103 to 147 properties per object.
While I can always add that count to an array, sort of like this:
$Array = @()
foreach ($T in $Test) {
#Get-ObjectType $T
$Array += $($T.PSobject.Properties.Name).Count
}
$Array | Sort-Object
And take the highest value and take all named properties from the one with highest properties count and then build my Excel/Word/SQL object based on that... there is:
a chance that the object with highest number of properties count doesn't really have the same properties like the one with the lowest number of properties
a big performance hit (I know that asking for all fields is a performance hit anyway)
Is there some other way to get a full set of results with all fields listed, even if they are empty for some records?
If you're wondering why I may need this think of creating a SQL table that will need all fields defined prior to inserting rows. Or an Excel workbook that will go row by row starting with header (which has to be known).