Populate a Data-Table from Get-ADUser command

I want to store the output from the Get-ADUser command into a Data-Table but, as far as I can tell, this command returns a System.Array. I know I can step through the array to populate a Data-Table but this is very slow.

Is there a way to store the output from the Get-ADUser command straight into a Data-Table?

Thanks.

What do you mean with

You could use Format-Table or Export-CSV.

I have data from a SQL SELECT statement which is stored in a DataTable object. I want to join this with the output from the Get-ADUser command for some later processing. Unfortunately this requires both sides to be DataTable objects.

Running the “$x = Get-ADUser | Format-Table” still results in $x.Get-Type() being System.Array so that doesn’t solve my problem.

You could use a PSCustomObject or calculated properties to combine properties of different objects. I could imagine that it would be helpful to see more of the code you’re using. :wink:

I’ve used this function (Out-DataTable) for Bulk Insert operations into SQL:

https://gallery.technet.microsoft.com/scriptcenter/4208a159-a52e-4b99-83d4-8048468d29dd