none
Trying to get "Get-ADUser -cred" into a script to query a list for SamAccountName RRS feed

  • General discussion

  • I have this...

    I am trying to get these details into this script:

    #get-aduser -Credential Logonname -Filter {Name -eq "Lastname, Firstname"} -Properties *|findstr /i /r  SamAccountName

    param ($inputfile='.\orientation_import.csv',$logfile='.\log.csv')
    $csv = Import-CSV $inputfile
    "samAccountName,Search Result" | Add-Content $logfile
    ForEach ($user in $csv)
    {
    $search = Get-ADUser -LDAPFilter cn=$($user.samAccountName)
    IF ($search) # if not empty or null
    {
    "$user.samAccountName, Found" | Add-Content $logfile
    }
    ELSE
    {
    "$user.samAccountName, Not Found" | Add-Content $logfile
    }
    }


    Patrick Burwell, Sr. Systems Engineer

    • Changed type Bill_Stewart Tuesday, July 31, 2018 3:16 PM
    • Moved by Bill_Stewart Tuesday, July 31, 2018 3:16 PM This is not "scripts on demand"
    Thursday, June 28, 2018 9:01 PM

All replies

  • Why are you piping to findstr? Are you trying to select a property? What is the purpose?

    Start slow. Try to explain in plain language what you are trying to do. (Tell what you want to do, not how you think it needs to be done.)


    -- Bill Stewart [Bill_Stewart]


    Thursday, June 28, 2018 9:09 PM
  • Get-AdUser does, in fact, have a credential parameter.

    if(Get-ADUser -Filter "SamAccountName -eq '$($user.samAccountName)'" -Credential $cred){
        #account found
    }else{
    
        #account not found
    }
    


    \_(ツ)_/

    Thursday, June 28, 2018 9:37 PM
  • Thanks, I was reading the wrong thing. I updated my comment.

    -- Bill Stewart [Bill_Stewart]

    Thursday, June 28, 2018 9:59 PM