none
Find Users in specific AD Groups RRS feed

  • คำถาม

  • Hello,

    I think i gave up, i was trying to make this script work, but i just dont know why i am getting the error message (at the end of the page).

    I just want to plug the userID of 1 user or users, and filter them to specific AD GROUP.

    I want to know if those users are part specific AD GROUPs

    Result:

    User1              Group 1

    User1              Group 2

    User2              Group 2

    User3              Group 1


    Import-Module ActiveDirectory
    $username = "User1"
    $Groups = (Get-AdGroup -filter * | Where {$_.name -like "Group*"} | select name -ExpandProperty name)
    $Table = @()
    $Record = @{
      "Group Name" = ""
      "Name" = ""
      "Username" = ""
    }
    Foreach ($Group in $Groups) {
    Get-ADUser $username -Identity $Group.name | select name,samaccountname
        $Record."Group Name" = $Group
        $Record."Name" = $username.name
        $Record."UserName" = $username.samaccountname
        $objRecord = New-Object PSObject -property $Record
        $Table += $objrecord
    }
    $Table | export-csv "C:\Users\User1\Desktop\Scripts\Users.csv"

    ERROR:

    Get-ADUser : A positional parameter cannot be found that accepts argument 'User1'.
    At line:1 char:1
    + Get-ADUser $username -Identity $Group.name | select name,samaccountna ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
        + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADUser

    16 สิงหาคม 2562 18:56

คำตอบ

  • Get-ADUser $username -Identity $Group.name

    That's your error it should be either

    Get-ADUser $username
    
    # OR
    
    Get-ADUser -Identity $username


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    • เสนอเป็นคำตอบโดย Stoyan ChalakovMVP 16 สิงหาคม 2562 21:37
    • ทำเครื่องหมายเป็นคำตอบโดย Hamid Sadeghpour SalehModerator 5 กันยายน 2562 20:17
    16 สิงหาคม 2562 19:55

ตอบทั้งหมด