locked
For each object array RRS feed

  • Question

  • I have a simple array with names I want to pass into a foreach-object command to find disabled users

    array -

    $a

    Sys Admin
    Bus Admin
    Manager

    $a | % {get-aduser -Properties displayname -Filter "extensionattribute6 -like '*514'" -SearchBase "ou=users,ou=$a,ou=Business Units,dc=biz,dc=com" -SearchScope "Subtree"}

    Any help would be appreciated.

    Wednesday, December 10, 2014 8:03 PM

Answers

  • $a='Sys Admin','Bus Admin',' Manager'
    $a | 
       %{
            get-aduser -Properties displayname -Filter "extensionattribute6 -like '*514'" -SearchBase "ou=users,ou=$_,ou=Business Units,dc=biz,dc=com" -SearchScope Subtree
        }
    


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Wednesday, December 10, 2014 9:12 PM
    • Marked as answer by AnnaWY Sunday, December 21, 2014 10:14 AM
    Wednesday, December 10, 2014 9:09 PM
  • That is not what you originally asked for, Please understand that this is not a free consulting forum.  We can answer specific questions but it is unfair to just keep changing your issue.

    I will give you one simple example then you will need to open a new question to pursue this:

    $filter="(extensionattribute6 -like '*514' -or extensionattribute6 -like '*66048') -and msRTCSIP-UserEnabled -eq $false"
    get-aduser -Properties displayname -Filter  $filter  -SearchBase 'ou=users,ou=$_,ou=Business Units,dc=biz,dc=com' -SearchScope Subtree
    


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Thursday, December 11, 2014 6:41 PM
    • Marked as answer by AnnaWY Sunday, December 21, 2014 10:14 AM
    Thursday, December 11, 2014 6:38 PM

All replies

  • Use Search-ADAccount instead.

    If you'd rather not, you need to adjust your searchbase and search based on the current item in the loop ($_ is used for this purpose).


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Edited by Mike Laughlin Wednesday, December 10, 2014 9:12 PM Update post, did not see $a was being used in the searchbase
    Wednesday, December 10, 2014 8:33 PM
  • $a='Sys Admin','Bus Admin',' Manager'
    $a | 
       %{
            get-aduser -Properties displayname -Filter "extensionattribute6 -like '*514'" -SearchBase "ou=users,ou=$_,ou=Business Units,dc=biz,dc=com" -SearchScope Subtree
        }
    


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Wednesday, December 10, 2014 9:12 PM
    • Marked as answer by AnnaWY Sunday, December 21, 2014 10:14 AM
    Wednesday, December 10, 2014 9:09 PM
  • Thanks!

    That works, with one problem, I would like to do something like...

            get-aduser -Properties displayname -Filter "extensionattribute6 -like '*514' -or extensionattribute6 -like '*66048' -and msRTCSIP-UserEnabled -eq $false" -SearchBase "ou=users,ou=$_,ou=Business Units,dc=biz,dc=com" -SearchScope Subtree

    I can't get the -and -or to work.  I've tried adding () but I don't think the | likes that.

    Ideas?

    Thursday, December 11, 2014 6:30 PM
  • That is not what you originally asked for, Please understand that this is not a free consulting forum.  We can answer specific questions but it is unfair to just keep changing your issue.

    I will give you one simple example then you will need to open a new question to pursue this:

    $filter="(extensionattribute6 -like '*514' -or extensionattribute6 -like '*66048') -and msRTCSIP-UserEnabled -eq $false"
    get-aduser -Properties displayname -Filter  $filter  -SearchBase 'ou=users,ou=$_,ou=Business Units,dc=biz,dc=com' -SearchScope Subtree
    


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Thursday, December 11, 2014 6:41 PM
    • Marked as answer by AnnaWY Sunday, December 21, 2014 10:14 AM
    Thursday, December 11, 2014 6:38 PM
  • I'm sorry, I didn't see it as a separate question, and I didn't mean to abuse the system.

    I appreciate the help.

    Thursday, December 11, 2014 6:59 PM
  • I'm sorry, I didn't see it as a separate question, and I didn't mean to abuse the system.

    I appreciate the help.

    It is clearly differnt form your first post.

    No problem but remember that part of the purposse of the forum is toproduce question/answer threads that are helpfule to others.   Yur second question was about the logic that you extened and had a new issue with how ti use compund logic expressions.  The original quesiton is about arrays.


    ¯\_(ツ)_/¯

    Thursday, December 11, 2014 8:01 PM