Using get-aduser to search for enabled users in entire domain filter ..

Hi,
my first post here.
I have the following problem. I am trying to figure out to create a powershell command (with get-aduser) that searches for only enabled
users (in the entire domain),  whose user account login names starts with "b" or "B" (because their user account login names are composed of Bnnnnn, n=numbers). I suppose that a string of "B*" in the command should be sufficient. The query result
must show the user account login name (Bnnnnn),  first name
and last name  and the enabled  (yes) status  of those enabled users. I would like to write the entire query result to a file (csv format), saving it to c: for example
Please help. Thanks in advance

I use -LDAPFilter mostly because I am used to the LDAP syntax. It can be used in PowerShell, VBScript, dsquery, VB, and many command line utilities (like Joe Richards' free adfind utility). Active Directory is an LDAP compliant database.
The PowerShell -Filter syntax can do the same things, but the properties it exposes are really aliases. I'm used to the AD attribute names, like sAMAccountName and userAccountControl. PowerShell uses things like "enabled" and "surname", which are aliases
you need to know or look up. For example, the Get-ADUser default and extended properties, with the actual AD attributes they are based on, are documented here:
http://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx
Finally, note that the "Name" property refers to the Relative Distinguished Name (RDN) of the object, which for user objects is the value of the cn attribute (the Common Name of the user). This may not uniquely identify the user, as it only needs to be unique
in the parent OU/container. The user login name (pre-Windows 2000 logon name) is the value of the sAMAccountName attribute, which must be unique in the domain. In the Wiki article I linked, we see that the PowerShell alias for this attribute is "SamAccountName"
(in this case the name of the property matches the name of the AD attribute). All of this can be confusing.
Richard Mueller - MVP Directory Services

Similar Messages

  • Comparing cmdlets: [search-adaccount -accountdisabled] vs. [get-aduser -ldapfilter "(&(objectcategory=person)(objectclass=user)(useraccountcontrol:1.2.840.113556.1.4.803:=2))"]

    Hello all,
    I have searched on Google but have not been able to find much information about a comparison between the following 2 cmdlets, which return a different ".count" number for the number of disabled users, so the underlying queries must be different
    and I'm wondering how:
    Search-ADAccount -AccountDisabled
    get-aduser -ldapfilter "(&(objectcategory=person)(objectclass=user)(useraccountcontrol:1.2.840.113556.1.4.803:=2))"
    I can of course tell what the second command is doing, but I can't find any explanations on what exactly the first cmdlet is doing.
    The only thing I can find is info from TechNet, on the [Search-ADAccount -AccountDisabled] cmdlet:
    "Specifies a search for accounts that are disabled. An account is disabled when the ADAccount Enabled property is set to false."
    I can't find any information on this "ADAccount Enabled" property. Does anyone know what this means, and what criteria this cmdlet is using to find disabled users?

    Thanks guys for all your responses. It turns out that removing the "person" and "users" parameters from the ldap filter in the cmdlet above removes the discrepancies between the 2 searches, such that the 2 commands below return the same
    number of objects:
    Search-ADAccount -AccountDisabled
    get-adobject -ldapfilter "(useraccountcontrol:1.2.840.113556.1.4.803:=2)"
    Also, interestingly enough, running the "Measure-Command" cmdlet on both of these commands a few times and in new instances of PowerShell each time for each cmdlet reveals that the bottom command is actually faster (running against
    a large domain):
    Search-ADAccount-AccountDisabled
    53.606 seconds
    53.540 seconds
    52.708 seconds
    get-adobject-ldapfilter"(useraccountcontrol:1.2.840.113556.1.4.803:=2)"
    46.385 seconds
    46.017 seconds
    45.936 seconds

  • How do I use Get-ADUser to get just the Managers attribute? And then get rid of duplicates in my array/hash table?

    Hello,
          I am trying to just get the Managers of my users in Active Directory. I have gotten it down to the user and their manager, but I don't need the user. Here is my code so far:
    Get-ADUser-filter*-searchbase"OU=REDACTED,
    OU=Enterprise Users, DC=REDACTED, DC=REDACTED"-PropertiesManager|SelectName,@{N='Manager';E={(Get-ADUser$_.Manager).Name}}
    |export-csvc:\managers.csv-append 
    Also, I need to get rid of the duplicate values in my hash table. I tried playing around with -sort unique, but couldn't find a place it would work. Any help would be awesome.
    Thanks,
    Matt

    I would caution that, although it is not likely, managers can also be contact, group, or computer objects. If this is possible in your situation, use Get-ADObject in place of Get-ADUser inside the curly braces.
    Also, if you only want users that have a manager assigned, you can use -LDAPFilter "(manager=*)" in the first Get-ADUser.
    Finally, if you want all users that have been assigned the manager for at least one user, you can use:
    Get-ADUser
    -LDAPFilter "(directReports=*)" |
    Select @{N='Manager';E={ (Get-ADUser
    $_.sAMAccountName).Name }}
    -Unique | Sort Manager |
    Export-Csv .\managerList.csv -NoTypeInformation
    This works because when you assign the manager attribute of a user, this assigns the user to the directReports attribute of the manager. The directReports atttribute is multi-valued (an array in essence).
    Again, if managers can be groups or some other class of object (not likely), then use Get-ADObect throughout and identify by distinguishedName instead of sAMAccountName (since contacts don't have sAMAccountName).
    Richard Mueller - MVP Directory Services

  • Get-rid of the format we get using Get-ADuser in a CSV. Send CSV data in an email in table format

    Hi,
    I am using get-ADuser in order to extract a few AD attributes of some users. I export the users and their respective attributes to a CSV. However, the output in CSV i get has the following format in each cell for its AD attribute. 
    @{description=<Value>} or @ { info=<Value>}
    I have tried to use Expandproperty switch in order to get rid of it but it does not accept null values and hence if a user has no value for a said attribute, the previous value is copied for that user too. However, without expand property it gives me the
    above format in the output.
    $Desc = Get-ADUser $Username -Properties description | select description
    I would like the cells to contain only values and not this format along.
    Also, once I have the CSV with values I would also like to copy the values from CSV in an email in the form of a TABLE. I have been able to copy the content in an email using the following however, this in not in a table format. 
    $mail = Import-Csv $newlogonfile | Out-String
    Please HELP!

    Yes I am already using Export-Csv but still getting the same kind of format in output :-
    $Username = $Event.Properties[5].Value
                $Title_var = get-aduser $Username -properties Title | select Title
           $Ofc_phone = get-aduser $Username -Properties OfficePhone | select OfficePhone
           $Info_var = get-aduser $Username -properties info | select info
           $Display_Name = get-aduser $Username -properties DisplayName | select DisplayName
                $Mail = Get-ADUser $Username -Properties Mail | select Mail
           $Desc = Get-ADUser $Username -Properties description | select description
            $Props = @{ 
                    User = $Event.Properties[5].Value;
                    TimeCreated = $Event.TimeCreated;
                    LogonType = $Event.Properties[8].Value;
                    DCName = $Event.MachineName;
    Workstation_address = $Event.Properties[18].Value;
    Title = $Title_var;
    OfficePhone = $Ofc_phone;
    Info = $Info_var;
    DisplayName = $Display_Name;
            Description = $Desc;
           EMail = $Mail
                $LogonRecord = New-Object -TypeName psobject -Property $Props
                $Result += $LogonRecord
    $Result | Export-Csv -Path $logFile -append -UseCulture -NoTypeInformation # Log it to CSV
    OUTPUT has values in this format in the CSV :-
    @{info=} @{description=abc} @{DisplayName=} @{Officephone=}
    @{Mail=[email protected]}

  • Do you ever get tired of searching for a solution and just want to TALK TO A HUMAN BEING?

    Do you ever get tired of searching for a solution and just want to TALK TO A HUMAN BEING?

    This is not Apple Technical Support. If you want to talk to Apple, you'd need to use the information provided using the Contact Us link at the bottom right of every page.
    This is a user-to-user forum. Most of us posting here are human beings.

  • Getting UWL task count for all users in a role.

    Hi.
    I recently posted a question regarding a very similar issue, but I haven't got any response yet. I think my question might have been somewhat poorly phrased, so I will try to do better at explaining what we need.
    We have a number of processes, most of which need to be dynamically assigned to a user when created. The way we want to assign those tasks is by executing a WebService which would receive a role name and get all the users for that role. Then, using the UWL API, it would check how many tasks each of the users have in their UWL, and return the UserID for whoever has the least tasks. I haven't been able to get this to work. I keep getting Logged in users context or session doesn't exist Exception.
    Please, any help on this will be greatly appreciated.
    Currently working with SAP NWDS 7.1 SP05 PAT0005

    Hi,
    Thank you for your response, however, that's not what I need.
    For you and anyone esle who might find this extra info useful...
    I know how to get a user's role(s), and how to get the users in a role.
    I also know how to assign a task to a specific user dynamically.
    Using the UWL API, I know how to get the tasks (or items) in a user's UWL from a WD application, I need to do that from a WebService and using pretty much the same code, with the necessary adjustments, I can't get it to work.
    Furthermore, I'm able to get the UWL tasks for ONE user, that user being the one I log into the application with. For example, if I write code to get the tasks for user testUser1, I need to log in with testUser1 to get it to work, if I log in with any different user or make it a non-authenticated application, it won't work.
    Again, help on this is much needed and will be appreciated.

  • Search for all user messages doesnot work now ?

    Hello SDNer's,
    I often search my own questions and posts entering the keywords in Search for all user messages. After our forum has been revamped this functionality seems not be working as it used to. When I enter the keywords and Enter it throws me results from Expert Forums instead showing results just from my ID/Username.
    Have anyone noticed this ?
    Please comment Mods.
    Happy New Year to all SDNer's !!!

    User search and monitoring was all disabled due to Privacy issues.

  • My iphone 4s gets stuck on "searching" for network after it runs out of battery

    My iphone 4s gets stuck on "searching" for network after it runs out of battery , i have to restart my handset repeatedly till it gets network why is this ? 

    Hello Andres.J,
    Thanks for using Apple Support Communities.
    Take a look at the following article, specifically steps 3-7 since you have already restarted the iPhone.
    iPhone: Troubleshooting No Service
    http://support.apple.com/kb/TS4429
    Take care,
    Alex H.

  • How to use the same POWL query for multiple users

    Hello,
    I have defined a POWL query which executes properly. But if I map the same POWL query to 2 portal users and the 2 portal users try to access the same page simultaneously then it gives an error message to one of the users that
    "Query 'ABC' is already open in another session."
    where 'ABC' is the query name.
    Can you please tell me how to use the same POWL query for multiple users ?
    A fast reply would be highly appreciated.
    Thanks and Regards,
    Sandhya

    Batch processing usually involves using actions you have recorded.  In Action you can insert Path that can be used during processing documents.  Path have some size so you may want to only process document that have the same size.  Look in the Actions Palette fly-out menu for insert path.  It inserts|records the current document work path into the action being worked on and when the action is played it inserts the path into the document as the current work path..

  • I can not store all my Music on my internal Macbook pro hard drive so I am storing it on a large external drive connected to my airport extrem.  How do I get Itunes to search for the music here with out trying to copy it to my laptops hard drive??

    I can not store all my Music on my internal Macbook pro hard drive so I am storing it on a large external drive connected to my airport extreme (2 TB drive plugged into the USB port).  I see the drive on my laptop and I can add and delete files no problem.  How do I get Itunes to search for the music here with out trying to copy it to my laptop's hard drive?  I don't have enough space to do that.

    How did you move the music to the external drive?  What exactly is on the drive?  The entire iTunes folder or only music?  If it is the entire iTunes folder you can do the option+start suggestion earlier.  If you copied only music and did so by dragging it there then you need to delete it again and consolidate/organize it there instead so iTunes tracks the move.  iTunes 12 for Mac: Change where your iTunes files are stored - http://support.apple.com/kb/PH19507

  • Can you use Find/Change to search for many different words at once?

    I have an 80 page catalogue in Indesign (CS5) - it has several thousands of catalogue numbers listed as text within it. I've just been given a list of 1000 catalogue numbers to search for and if they appear, remove them - is there any way to search for them all in one go, rather than one by one?
    I've started using Find/Change to search for the catalogue numbers but seem to only be able to search one catalogue number at a time that way.
    Any ideas welcome!
    Thanks

    GREP can search for more than one phrase "at once" (i.e., in one operation), like this:
    word1|word2|word3
    -- the pipe | delimits the separate words. Then again, GREP Is Not Magic™. This --
    ...  a list of 1000 catalogue numbers to search for ...
    is a bit too much to copy-and-paste into the single Find What line. There is a limit of ten or twelve (or something) OR phrases you can use in GREP.
    On the other hand: GREP is great at finding numbers. If all of your catalogue numbers obey some basic rule, for instance "all of them consist of 6 digits and there are no other numbers with exactly 6 digits", well, that we can probably work with.

  • How can I allow or block the use of local storage by specific sites for all users in my domain.

    How can I allow or block the use of local storage by specific sites for all users in my domain.
    I tried to do this by MMS.cfg but it is not working, the problem is also described in your blog "http://forums.adobe.com/message/3272907".
    What I Want -: "I want to allow youtube for all the users in my domain and this should be listed in Control panel-->flash player-->storage-->local storage setting by site-->websites tab."

    Wow, cor-el... Did you -intend- your reply to be inane, inappropriate and completely inapplicable?
    How would that possibly do what I asked?
    You -might- consider '''''reading''''' the question, -=before=- you reply. And it's really okay to NOT REPLY if you just don't know. Just an idea.
    Feel better, real soon.

  • Can i use the same email address for different users?

    we are a small department with one email address, can i use the same email address for different users?

    No. Each user needs to have his unique ID.
    Mylenium

  • In Linux, my firefox uses the /etc/firefox profile for all users, now I need ONE user only to start with their own profile, I'm struggling to achieve this, please help!

    In Linux, my firefox uses the /etc/firefox profile for all users, now I need ONE user only to start with their own profile, I'm struggling to achieve this, please help!

    .Jake. wrote:
    I forgot to say that the hard drive has not been used yet...
    So you have no backup of your data at all?
    Pete

  • Is it legal to ban the use of Network Magic Pro for registered users

    Hi 
    I have a question ... Is it legal to ban the use of Network Magic Pro for registered users
    Cisco would he have to propose a solution : patch, reg file or other solution
    Because it's certainly enough to modify one or more files to make Network Magic Pro registered ...
    Regards.
    Daniel

    Hi Daniel,
    I'm not sure if it's still possible to create a solution to it. I believe Cisco and Pure Networks (Network Magic) has ended their partnership since last year.

Maybe you are looking for

  • Javascrip to read Header text in pdf

    Hi all I'm new to use javascritp in PDf , i used javascript in Photoshop and illustrator i'm new to PDF i need a script to read header text in all pages of pdf where font, fontsize must be same Please anyone help me to develop script

  • Function to change DataType member names

    I was wondering if (TestStand 4.2) contains the ability to call all referrences to a Data Type member used in a sequence to be changed to the new name if that DataType member is renamed in the MyTypes.ini file? Solved! Go to Solution.

  • SharePoint 2013 & SQL Server Reporting Services

    Hi there, We are developing a web application in sharepoint 2013 in which we are using authentication mode="Windows".  We have used a custom web part containing report viewer control for showing charts and reports, that we have developed using SSRS (

  • Os 10.4, xp and linux. triple boot

    Is there any way to have Mac OS 10.4.10, Microsoft XP service pack 2 Professional and Linux all on the same computer. I already have XP installed with bootcamp but, I wanted to try out Linux. I have looked at some ways to dual boot linux and mac and

  • Catalyst 2950-EMI, QoS, traffic classification and shaping

    Dear All, Can 2950-EMI perform traffic classification and shaping? Let's say I have some workstations attached on my 2950 and I want to perform traffic classification and shaping on the uplink based on the IP address of workstations. Thanks a lot. ma