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

    15/ذو الحجة/1440 06: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''

    15/ذو الحجة/1440 07:55 م

جميع الردود

  • 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''

    15/ذو الحجة/1440 07:55 م
  • Thank you so much!!!!

    That fixed one issue, now I have another one...

    The RECORD instruction that I wrote (same script) is not saving name and samaccountname

    it does not show any errors in the powershell, but the csv does not show the name and samaccountname, it only shows the Group Name

    15/ذو الحجة/1440 08:27 م
  • There are numerous scripts in the Gallery that can do what you are trying to do. Look at those scripts to see a number of ways to solve your problem.


    \_(ツ)_/

    15/ذو الحجة/1440 08:36 م
    المشرف
  • To get all of the mebers of a group:

    Get-AdGroupMember 'Domain Users'

    For multiple groups:

    $groups | Get-ADGroupMember


    \_(ツ)_/


    • تم التحرير بواسطة jrvModerator 15/ذو الحجة/1440 10:15 م
    15/ذو الحجة/1440 10:14 م
    المشرف