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

คำตอบ

ตอบทั้งหมด