Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Active Directory and PowerShell

Thread: searching all users in forest

This question is answered.


Permlink Replies: 4 - Pages: 1 - Last Post: Dec 18, 2009 1:17 AM by: Andrey Moiseev ...
RTeal

Posts: 27
Registered: 11/20/09
searching all users in forest
Posted: Dec 15, 2009 2:54 PM
 
  Click to reply to this thread Reply

Hello,

I'd like to get a list of all users whose passwords are set to never expire in the entire forest. However, the -searchroot command reports "method not supported"

get-qaduser -searchroot dc=mycomp,dc=com | where {$_.passwordneverexpires -eq "true"}|select name,domain

How can I search the entire forest?

Thanks





Andrey Moiseev (Quest)

Posts: 415
Registered: 9/4/07
Re: searching all users in forest
Posted: Dec 17, 2009 2:41 AM   in response to: RTeal
 
  Click to reply to this thread Reply

connect-qadservice 'forest.com' -gc
get-qadobject -ou 'DC=forest,DC=com' -type domainDNS | %{get-qaduser -ou $_ -sl 0} | ?{$_.PasswordNeverExpires} | ft Name, Domain


RTeal

Posts: 27
Registered: 11/20/09
Re: searching all users in forest
Posted: Dec 17, 2009 11:08 AM   in response to: RTeal
 
  Click to reply to this thread Reply

This works very well but I get GUIDs for domains other than the one I am logged in to. Is there a way correct this?

In this expression %{get-qaduser -ou $_ -sl 0} | ?{$_.PasswordNeverExpires} am I correct that %=for each, ?=where ?
What does -sl 0 mean?

Thank you



RTeal

Posts: 27
Registered: 11/20/09
Re: searching all users in forest
Posted: Dec 17, 2009 11:51 AM   in response to: RTeal
 
  Click to reply to this thread Reply

Also, when I |export-csv filename.csv
the output comes out as numbers
Do you know how I can correct this format issue?
<table border="0" cellspacing="0" cellpadding="0" width="384" style="width: 288pt; border-collapse: collapse"> <tbody> <tr height="19" style="height: 14.4pt"> <td colspan="4" width="256" height="19" style="background-color: transparent; width: 192pt; height: 14.4pt; border: #ece9d8">033ecb2bc07a4d43b5ef9898a35d280</td> <td colspan="2" width="128" style="background-color: transparent; width: 96pt; border: #ece9d8">Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo</td> </tr> </tbody></table>


Andrey Moiseev (Quest)

Posts: 415
Registered: 9/4/07
Re: searching all users in forest
Posted: Dec 18, 2009 1:17 AM   in response to: RTeal
Answered
  Click to reply to this thread Reply

Yes, you're right:
% = For-Each
? = Where-Object
sl 0 = SizeLimit 0
ft = Format-Table

Excuse me for a bit cryptic code, I just experimented and copied results virtually "as is".
Your formatting issue is because I've used Format-Table instead of your initial Select-Object. My bad also.:)
Format-* cmdlets are for formatting only, they're not suitable for export. Just use Select-Object.

I didn't catch what's your problem with GUIDs, can you write an example of output to clarify it?




Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums