Meilleur auteur de réponses
Find Users in specific AD Groups

Question
-
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
Réponses
-
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''
- Proposé comme réponse Stoyan ChalakovMVP vendredi 16 août 2019 21:37
- Marqué comme réponse Hamid Sadeghpour SalehModerator jeudi 5 septembre 2019 20:17
Toutes les réponses
-
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''
- Proposé comme réponse Stoyan ChalakovMVP vendredi 16 août 2019 21:37
- Marqué comme réponse Hamid Sadeghpour SalehModerator jeudi 5 septembre 2019 20:17
-
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
-
-
To get all of the mebers of a group:
Get-AdGroupMember 'Domain Users'
For multiple groups:
$groups | Get-ADGroupMember
\_(ツ)_/
- Modifié jrvModerator vendredi 16 août 2019 22:15