Ben_the_Terrible
Ben_the_Terrible

Reputation: 201

Get-ADuser Search Issues

Ok, I know this is probably a simple mistake I'm making, and it might be in here somewhere, but I can't find it.

I'm used to using the Get-QADuser cmdlet, but I now have to write a quick script that utilizes the Get-ADuser cmdlet, which I've never actually used and am not familiar with. Here's the code:

$litholdinfo = Get-ADUser -Filter * -Properties samaccountname, cn, lastknownparent, extensionattribute2

I run that, but nothing happens. It just sits there and doesn't pull any data. What am I doing wrong?

Upvotes: 0

Views: 121

Answers (1)

Gus Whitehouse
Gus Whitehouse

Reputation: 118

You are not doing anything wrong. You've pushed the result into a variable but you aren't doing anything further with the variable.

See below a slight adjustment to your code. the -properties switch is only used to pull extended properties, you don't need to call samaccountname. Also, you can speed up your search by providing a starting Container to search from. Define a specific container if you indeed manage your user accounts all in a central location.

# Query AD and store in variable
$litholdinfo = Get-Aduser -filter * -properties cn,lastknownparent,extensionattribute2 -searchbase "ou=userOU,dc=domain,dc=com";

#Display variable contents in console
$litholdinfo | Select samaccountname,cn,lastknownparent,extensionattribute2

Upvotes: 1

Related Questions