Striper Talk Striped Bass Fishing, Surfcasting, Boating

     

Left Nav S-B Home FAQ Members List S-B on Facebook Arcade WEAX Tides Buoys Calendar Today's Posts Right Nav

Left Container Right Container
 

Go Back   Striper Talk Striped Bass Fishing, Surfcasting, Boating » Striper Chat - Discuss stuff other than fishing ~ The Scuppers and Political talk » Computers

Computers Sidetrack to Computers, Questions on your home computer? Posting just for registered members....

Reply
 
Thread Tools Rate Thread Display Modes
Old 10-17-2007, 07:24 PM   #1
BrianS
Canal Junkie
iTrader: (4)
 
BrianS's Avatar
 
Join Date: May 2003
Location: Raynham
Posts: 1,678
Send a message via AIM to BrianS
C# and Active Directory ***geeky programming question warning***

I have a problem in that I am looking to pull a list of users from Active Directory into my application.

I actually have it working in that I have pulled ALL "users" in, but its also bringing in users that are Inactive.

How can I designate and only pull in "active" users?

This is my code as it works now.. Any assistance would be GREATLY appreciated.


try
{
string path = "LDAP://bosdc1/CN=Users,DC=firm,DC=gsxxx,DC=com";
DirectoryEntry AD = new DirectoryEntry(path);
AD.Username = "GS\\xxxxx";
AD.Password = "xxxxx";

AD.Username = "GS\\xxxxx";
AD.Password = "xxxxx";
AD.Children.SchemaFilter.Add("user");


foreach (DirectoryEntry obj in AD.Children)
{
string replaced = FixString(obj.Name.ToString(), "CN=", "");
replaced = FixString(replaced, "\\", "");
ADUsersList.Items.Add(replaced);
}
}
catch
{
}

aim: SaltedBrian
BrianS is offline   Reply With Quote
Old 10-19-2007, 01:25 PM   #2
fishsmith
DDG-51
iTrader: (0)
 
fishsmith's Avatar
 
Join Date: Mar 2002
Posts: 3,550
Thread Starter: BJSusol Started: 19 Oct 2007 4:35 PM UTC Replies: 1


This looked interesting and I started looking ..... ain't it funny what google will bring up.

My suggestion for you is a quick and dirty two step process, get the full list then filter out the inactives.

Good luck
fishsmith is offline   Reply With Quote
Old 10-19-2007, 02:22 PM   #3
The Dad Fisherman
Super Moderator
iTrader: (0)
 
The Dad Fisherman's Avatar
 
Join Date: Sep 2003
Location: Georgetown MA
Posts: 18,203
Can you do something like an ifmember statement and then pick certain groups...just a thought

"If you're arguing with an idiot, make sure he isn't doing the same thing."
The Dad Fisherman is offline   Reply With Quote
Old 11-18-2007, 07:28 PM   #4
ThrowingTimber
It's about respect baby!
iTrader: (0)
 
ThrowingTimber's Avatar
 
Join Date: Apr 2003
Location: ri
Posts: 6,358
Blog Entries: 1
maybe set it to collect logins within the past 90 days.

Domination takes full concentration..
ThrowingTimber is offline   Reply With Quote
Old 11-20-2007, 01:13 PM   #5
BrianS
Canal Junkie
iTrader: (4)
 
BrianS's Avatar
 
Join Date: May 2003
Location: Raynham
Posts: 1,678
Send a message via AIM to BrianS
This is what I did

try
{
string path = "LDAP://xxxx/CN=Users,DC=firm,DC=xxxx,DC=com";
string filter = "(&(objectCategory=person)(objectClass=user)(!user AccountControl:
1.2.840.113556.1.4.803:=2))";
string[] propertiesToLoad = new string[1] { "name" };

using
(DirectoryEntry root = new DirectoryEntry(path, "xx\\xxxx", "xxxx"))
using (DirectorySearcher searcher =
new DirectorySearcher(root, filter, propertiesToLoad))
using (SearchResultCollection results = searcher.FindAll())
{
foreach
(SearchResult result in results)
{
string name = (string)result.Properties["name"][0];

ADUsersList.Items.Add(name);
}
}
}
catch
{
}

The search filter syntax looks a bit complicated, but basically it filters the search results to only include users - "objectCategory=person" and "objectClass=user" - and excludes disabled user accounts by performing a bitwise AND of the userAccountControl flags and the "account disabled" flag, and negating the results.

aim: SaltedBrian
BrianS is offline   Reply With Quote
Old 11-24-2007, 11:34 AM   #6
JohnR
Certifiable Intertidal Anguiologist
iTrader: (1)
 
JohnR's Avatar
 
Join Date: Feb 2000
Location: Somewhere between OOB & west of Watch Hill
Posts: 35,270
Blog Entries: 1
No scripting but you could put your inactives into a separate OU and then export from adduser.exe (or userad.exe forget which) into a text file -> CSV -> excel

~Fix the Bait~ ~Pogies Forever~

Striped Bass Fishing - All Stripers


Kobayashi Maru Election - there is no way to win.


Apocalypse is Coming:
JohnR is offline   Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:48 PM.


Powered by vBulletin. Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Please use all necessary and proper safety precautions. STAY SAFE Striper Talk Forums
Copyright 1998-20012 Striped-Bass.com