How do I run Get-ADUser and filter out two separate OUs

Ha! I was assuming that Where-Object wouldn't do me any better. Well, I guess I made an ass out of me. ;)
Your first script is what I will use. We have some user accounts in other OUs that are disabled for other reasons.
It's little quirks like this that keep me from using Powershell more often.
Thanks Matt!

Hi again all!I am trying to write a script that will search for AD users that have the "Password Never Expires" box checked, but not if they are in one of two OUs. These OUs are not parent/child, they are separate.If I run this, I get about 30 results:
Powershellget-aduser -filter { PasswordNeverExpires -eq $true }Some of the results are in the "Disabled Accounts" OU, some are in the "Contractors" OU, and the rest are in neither.
If I run either of these, I get zero results:
Powershellget-aduser -filter { PasswordNeverExpires -eq $true -and DistinguishedName -notlike "*Disabled*"}get-aduser -filter { PasswordNeverExpires -eq $true -and ( DistinguishedName -notlike "*Disabled*" -and DistinguishedName -notlike "*Contractors*")}I know for a fact that I have users that are not in either of these two OUs that have that box checked because I...
This topic first appeared in the Spiceworks Community

Similar Messages

  • How can i run snow leopard and leopard in my mac?

    how can i run snow leopard and leopard in my mac?

    First, your Mac model must be able to run Leopard. Second, you would have to partition your hard drive to create a second volume then install Leopard on the new volume using a Leopard installer DVD.

  • Get-messagtrackinglog and filter by RemoteIpRanges

    Hello,
    Exchange 2010 sp3
    Is it possible to perform a get-messagtrackinglog and filter by RemoteIpRanges? I want to know whether a specific ip address is sending mail messages to the send connector?

    Hi,
    Agree with Amit. We can use ConnectorID to specify the destination Send connector or Receive connector. You can refer to this article below.
    http://technet.microsoft.com/en-us/library/bb124375(v=exchg.141).aspx
    Best regards,
    Belinda
    Belinda Ma
    TechNet Community Support

  • How i can "apt-get autoremove" and "autoclean" like debian based?

    hi, i would like to know how to do "apt-get autoremove" and "apt-get autoclean" like debian based linux in arch for cleaning the system?
    thanks you for this community....

    BTW: With Arch, you don't have to! (TM) Or that's the impression I have anyway. See the remove options, there are flags which basically allow you to remove 'unneeded' stuff -when- it becomes unneeded.
    For example:
    Debian:
    apt-get install sniffles - also installs libsniffle, libsniffle-dev
    apt-get --purge remove sniffles - leaves libsniffle, libsniffle-dev which then have to be removed via autoremove. I'm not sure under what circumstances this won't even work and you'll end up having to use deborphan or somesuch
    Arch:
    pacman -S sniffles - also installs libsniffle, libsniffle-dev
    pacman -Rcns sniffles - also removes libsniffle and libsniffle-dev
    Perfect operating system:
    <package manager> <install option> sniffles - laughs and blames it on temporary insanity that you'd want to install anything having anything to do with sniffles.

  • How to print the row  ,column,and particular cell in separate color

    how to print the row  ,column,and particular cell in separate color IN ALV GRID

    HI,
    Here you go good program links
    <a href="http://www.sapfans.com/forums/viewtopic.php?t=52107">How to Set Color to a Cell in AVL</a>
    <a href="http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm">ALV Grid Coloring</a>
    Thanks
    Mahesh

  • How to check ,how many  users are logged in and logged out in oracle ebs 11i/R12.

    Hi Experts,
    Kindly let me know
    how to check ,how many  users are logged in and logged out in oracle ebs 11i/R12.
    Also, in the database level too ,Do we need to write any trigger for this?
    Thanks in advance.

    Hi,
    How to check ,how many  users are logged in and logged out in oracle ebs 11i/R12.
    Please check the following links:
    Oracle EBS - Number of Users logged into EBS / Oracle Applications currently
    List all users currently logged in on Oracle EBS
    Also see forum Search:
    Forum Search: Logged In EBS User
    Also, in the database level too
    Please see:
    https://forums.oracle.com/message/9225094#9225094
    Do we need to write any trigger for this?
    Yes you may, But I personally suggest you not to do so as it may affect performance.
    Thanks &
    Best Regards,

  • How to use same Data Type and Length for two fields

    How to use same data type and length for two fields when using 'FOR ALL ENTRIES IN' in a select statement? For instance the select queries are :
    SELECT bukrs gjahr belnr lifnr budat bldat zlspr dmbtr waers shkzg
    FROM bsik
    INTO TABLE it_bsik
    WHERE bukrs = p_bukrs
    AND lifnr IN s_lifnr.
    IF it_bsik IS NOT INITIAL.
    SELECT belnr gjahr awkey awtyp
    FROM bkpf
    INTO TABLE it_bkpf
    FOR ALL ENTRIES IN it_bsik
    WHERE belnr = it_bsik-belnr
    AND gjahr = it_bsik-gjahr.
    IF it_bkpf IS NOT INITIAL.
    SELECT belnr gjahr lifnr xblnr
    FROM rbkp
    INTO TABLE it_rbkp
    FOR ALL ENTRIES IN it_bkpf
    WHERE belnr = it_bkpf-awkey+0(10)
    AND gjahr = it_bkpf-awkey+10(4).
    ENDIF.
    ENDIF.
    Here it gives an error in the 3rd select query that 'When you use the addition "FOR ALL ENTRIES IN itab", the fields "GJAHR" and "IT_BKPF2-AWKEY+10(4)" must have the same type and the same length.'
    Kindly clarify.

    Hi Saurabh,
    Please see the example code that I have developed for you. It will help you solve the problem.
    REPORT ZTEST_3 .
    tables : BKPF.
    data : begin of it_bkpf occurs 1,
             belnr type RE_BELNR,
             awkey type awkey,
             awtyp type awtyp,
             gjahr type GJAHR,
           end of it_bkpf.
    data : begin of it_bkpf1 occurs 1,
             belnr type RE_BELNR,
             awkey type gjahr,              " change the data type
             awtyp type awtyp,
             gjahr type GJAHR,
           end of it_bkpf1.
    data : begin of it_rbkp occurs 1,
             belnr type BELNR_D,
             gjahr type gjahr,
             lifnr type LIFRE,
             xblnr type XBLNR,
           end of it_rbkp.
    select belnr
           awkey
           awtyp
           gjahr
           from bkpf
           into table it_bkpf
           where BUKRS = 'TELH'.
    loop at it_bkpf.
    it_bkpf1-belnr = it_bkpf-belnr.
    it_bkpf1-awkey = it_bkpf-awkey+10(4).           "Here only append the required length.
    it_bkpf1-awtyp = it_bkpf-awtyp.
    it_bkpf1-gjahr = it_bkpf-gjahr.
    append it_bkpf1.
    clear it_bkpf1.
    endloop.
    select  belnr
            gjahr
            lifnr
            xblnr
            from RBKP
            into table it_rbkp
            for all entries in it_bkpf1
            where belnr = it_bkpf1-belnr
    This is just an example. Change the fields according to your requirement.
    Regards
    Abhii
    Edited by: Abhii on Mar 9, 2011 9:08 AM

  • Very Urgent (How can i add fade in and fade out Action)

    Hi, How can i add fade in and fade out action on the JButton when the mouse is over the button.its mean that when the mouse is over the button then the button's Label is fade in and out.
    plz give code example
    thanks

    If you want to fade in and out anything, you should look at the Composite interface. A Composite is part of a Graphics2D object. You should be able to gradually change this on the button, but maybe within a different thread?

  • How can i run my java program with out java language

    Hai to every one ..Iam new to java language ...am using windows xp operating system , i did not installed java language in my system .. how can i run a java program with out installing java language... Which files is requied to run java program..?
    any one can help me??

    Hai to every one ..Iam new to java language ...am
    using windows xp operating system , i did not
    installed java language in my system .. how can i run
    a java program with out installing java language...
    you ... can ... not ... do ... this
    Which files is requied to run java program..?
    any one can help me??a JVM. Download it from sun's website.
    [url http://java.sun.com/javase/downloads/index.jsp]Download JavaSE here

  • Photos in my from my iPhone have same numbering as photos from my dig camera.  They all go into iPhoto fine but when I backup to my ext hard drive it will only save one with the name IMG 1002 and I have two separate images both with that name.  Help?

    Photos in my from my iPhone have the same numbering as photos from my digital camera.  They all go into iPhoto fine but when I backup to my ext hard drive it will only save one with the name IMG 1002 and I have two separate images both with that name.  How do I get them all to save on my ext hard drive and hope do I prevent this numbering overlap in the future?  I'm really hoping I don't have to go through and manually rename every single picture.  Thanks.

    How are you backing up the photos?  The best way is to backup the library itself as that will preserve your organizational efforts as well as all metadata like keywords, titles, faces, places, books, etc.
    You can use a backup application that does incremental backups.  Thus only the first backup is a full one and subsequent backups just copy those files that are new or changed. I use Synk Pro.  The lower cost version, Synk, will do the same job.  Other similar apps can be found at MacUpdate.com.  
    OR: upload your camera to a folder on the Desktop. There you can rename the files to something that is more informative than just the file name.  I use the date (international format) along with a brief desc: 2007-1-20-adian1stbday-001.jpg.  File renaming apps can also be found at MacUpdate.com.  Also you can give the folder an informatve name which will become the Event name when you import the folder of photos into iPhoto.
    OT

  • How do I maintain a single iTunes library for two separate iMac user accounts?

    How do I maintain a single iTunes library for two separate iMac user accounts?...without having to manually do something every download?

    Pardon me, I am brand new at using an iMac.  I understand the concept but I don't know exactly how to "move" the library.  I found a shared folder under users on the hard drive.  If I move it, won't I have to redirect each iTunes user to the new shared location?
    If I point iTunes to anything other than the music folder under that user name, it shows as a "shared library".  Preferences still shows it as that users library, regardless of where the advanced gear button says it is pointing to.
    Am I asking for too much to have each user control the exact same music files, apps and playlists?  I just want the two different itunes sessions to mirror each other without any frequent updating or copying.
    We use the same id for itunes music and apps so we could just sync all devices under one iMac user id and not use it under hers.

  • 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-ADUser and Get-ADPrincipalGroupMembership combined

    I'm trying to get a list of template user account and what their membership are exported to a csv file. I'm trying to combine the tables on them but having a hard time figuring it out. I spent the day racking my brain on this and figured I would reach out
    for help. This gets all my template users.
    Import-Module ActiveDirectory
    $User = "*Template*"
    $usernames = (Get-ADUser -Filter "DisplayName -like '*$User*'" -Properties * | format-table Displayname, SamAccountName)
    $usernames
    I can use this to get all the members of the groups, but since the groups repeat it doesnt break down where one user stops and the others begin. 
    $groups = Get-ADUser -Filter "SamAccountName -like '*$Usr*'" -Properties DisplayName | foreach-object{Get-ADPrincipalGroupMembership -Identity $_.SamAccountName} | format-table name
    I was thinking of joining the tables but that wasnt much help to me since I cant figure out what to join on. I also thought about looping through the first table with a foreach loop but it was assigning the whole table in the first pass and displaying nothing.
    If anyone could help or suggest something, I would greatly appreciate.
    Matt

    Hi Matt,
    Give this a shot:
    Get-ADUser -Filter "DisplayName -like '*Template*'" -Properties MemberOf | ForEach {
    $username = $_.SamAccountName
    $_.MemberOf | ForEach {
    $props = @{
    Username = $username
    GroupName = (Get-ADGroup $_).Name
    New-Object PsObject -Property $props
    } | Sort Username,GroupName |
    Select Username,GroupName |
    Export-Csv .\GroupMemberships.csv -NoTypeInformation
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • Get-ADuser and formatting results

    What Im looking to do is to output all of my AD Users, including all of their properties, and then output that to a tabular format. The issue I am having is that some of the fields, like MemberOf, dont come through. My script looks like the following:
    Get-ADuser -Filter * -Properties * | Export-CSV C:\Temp\MyFile.csv
    This is almost what I want, but I just need for all of the properties to be expanded. Some end in "..." meaning there is more to be shown, and others such as "MemberOf" show "Microsoft.ActiveDirectory.Management.ADPropertyValueCollection" instead of showing
    the actual groups.
    Thanks in advance for any help!
    Jarrod Sturdivant [email protected]

    I had the same question and the "Exchange Proxy Address (alias) Report" Blog entry helped me a lot in this case.
    Here is my adaption
    $multipcgroups = @()
     $Pclist = import-csv mypclist.csv | foreach {get-adcomputer -identity $_.name -Properties * | select name, memberof}
     foreach ($pc in $pclist) {
     [array]$pcgroups = $pc.memberof
    $ErrorActionPreference = 'SilentlyContinue'
     $pcadgroup = New-Object PSObject -Property @{
    Name = $pc.name
     pcadgroup0 = $pcgroups[0] -replace "OU=SW,OU=Groupx,OU=foo,DC=company,DC=de" -replace "OU=Filter,OU=Technical Roles,DC=company,DC=de"
    pcadgroup1 = $pcgroups[1] -replace "OU=SW,OU=Groupx,OU=foo,DC=company,DC=de" -replace "OU=Filter,OU=Technical Roles,DC=company,DC=de"
    pcadgroup2 = $pcgroups[2] -replace "OU=SW,OU=Groupx,OU=foo,DC=company,DC=de" -replace "OU=Filter,OU=Technical Roles,DC=company,DC=de"
    $ErrorActionPreference = 'Continue'
     $pcadgroupCount = ($pcgroups).count
     if ($pcadgroupCount -gt 0) {
    $multipcgroups += $pcadgroup
     $multipcgroups | select name, pcadgroup0,pcadgroup1,pcadgroup2 | Export-CSV pcadgroups.csv -notype
    regards
    Andreas

  • Get-AdUser and a other domain

    I'm having problems running a script to search all accounts on a Domain.
    I want to be able to switch domain choices
    Current script is:
    Import-Module activedirectory
    Get-ADUser -Filter * -Properties * |
    Select-Object Name,LastLogonDate | export-csv C:\users.csv -notypeinformation
    I've tried the following to no avail - still outputs my domain not the selected:
    import-module activedirectory
    $data =@()
    $domains = "another.domain.com"
    foreach($domain in $domains)
     $data += Get-ADUser -Filter * -Properties * | Select-Object Name,LastLogonDate
    $data | export-csv C:\users.csv -notypeinformation
    Any ideas?

    Hi ESXi,
    I’m writing to just check in to see
    if the suggestions were helpful. If you need further help, please feel free to reply this post directly so we will be notified to follow it up.
    If you have
    any feedback on our support, please click here.
    Best Regards,
    Anna Wang
    TechNet Community Support

Maybe you are looking for

  • ITunes install fails due to Error Code

    I'm trying to install iTunes and I get the message Service 'Apple Mobile Device' failed to start. Verify you have sufficient privileges to start system services. I then have 3 options - Abort - Retry - Ignore which provide no success. If I ignore it

  • Photoshop Elements 11 Organiser does not start from the welcome screen

    Having installed Photoshop Elements 11(Windows 7)  I cannot open the Organiser from the welcome screen. It can be opened via the Editor but few of the thumbnails are shown as pictures rather as empty squares. The situation does not improve with time

  • Macbook (white) to external display help

    I would like to know that if you get this(http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=220302853762&_trksid=p2759. l1259) adapter for the mini dvi-d port on my macbook will it work with a dvi-d display and cable due to it being a dvi-i adapte

  • Outlook 2007 hangs when Calendar tab is clicked

    I am using Windows Vista on a Sony Notebook with Outlook 2007 SP1 connected to exchange server 2003.  I had a problem that my outlook worked fine except for one thing: it hanged whenever I clicked on the calendar tab.  I then had to restart my outloo

  • Enabling Hardware Accelearation in FireFox 31, plus Other Tips on Making FF 31 work faster

    FireFox 31 has been extremely sluggish on my computer. When I try to open a new tab or browser, the "wheel of doom" appears and the action pauses for 15 seconds to one minute. At the same time message will temporarily pop up that says "FireFox is not