Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


List all users or computers in the default domain

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,35650
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> List all users or computers in the default domain
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 List all users or computers in the default domain - 6/22/2006 12:01:37 AM   
  ginolard


Posts: 1020
Score: 21
Joined: 8/10/2005
Status: offline
Sniff.  My first PowerShell script.  It's like being a new dad all over again.

Save the script with a .ps1 extension and run it via the Powershell command.  The script accepts either the parameter USERS or COMPUTERS

$de = New-Object directoryservices.directoryentry('LDAP://rootDSE')
$Root = New-Object directoryservices.directoryentry("LDAP://$($de.DefaultNamingContext)")
$searcher = new-object System.DirectoryServices.DirectorySearcher($root)

switch ($args[0]) {
"computers" {$searcher.Filter="(&(objectCategory=computer))"}
"users" {$searcher.Filter="(&(objectCategory=person)(objectClass=user))"}
default {"Please specify either USERS or COMPUTERS.";Exit}
}

$searcher.PageSize = 1500
$searcher.PropertiesToLoad.Add("cn")
$searcher.sort.PropertyName="cn"
$ADItems = $searcher.findAll()
foreach ($user in $AdItems){$user.properties.cn}

< Message edited by ginolard -- 6/22/2006 1:07:36 AM >


_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> List all users or computers in the default domain Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts