Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

`Get-ADUser | Select-Object` extremely slow compared to Get-ADComputer

$
0
0

I am trying to pull down AD information to dump into an SQLite DB along with other data sources so I can quickly run reports. The dump part works fine – it uses the PSSQLite module and the Invoke-SQLiteBulkCopy cmdlet which efficiently adds objects to the DB by matching property names to field names. However, the object properties must match the table fields or the copy fails. This means I have to filter the properties using Select-Object. Pretty straight forward so far…

The problem is that I discovered that using Select-Object on ADUser objects takes over 100x longer than ADComputer objects.

I’ve made a sample script to illustrate this:

Source: https://pastebin.com/qb6cFEvL
Output: https://pastebin.com/Z84Jt3DT

(Note: watch out for the array slicing on Get-ADForest results – this was done specifically for testing in my environment, so change if needed)

I’ve got a few clues about what is going on.

First is the note on the ActiveDirectory module docs.

“Both the default and extended properties are really methods”

Second, when I look at network traffic when Select-Object is running I see lots of traffic to the DC, whereas I see none when selecting through ADComputer objects.

I would have to guess that the ADUser object property Get methods are calling out to the DC to fetch values instead of being retrieved in the original Get-ADUser query.

So my questions are:

  • Why does this happen with ADUser objects but not ADComputer objects?
  • How can I force PowerShell to retrieve the object properties up front instead of during each iteration of the Select-Object pipeline?

Running through all of our domains’ computer objects takes just a few minutes which is very good, but if I can’t get it to process the user objects in less than a few hours my approach may be unviable.

submitted by /u/Nu11u5
[link] [comments]

The post `Get-ADUser | Select-Object` extremely slow compared to Get-ADComputer appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles