Usuário com melhor resposta
Find Users in specific AD Groups

Pergunta
-
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
Respostas
-
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''
- Sugerido como Resposta Stoyan ChalakovMVP sexta-feira, 16 de agosto de 2019 21:37
- Marcado como Resposta Hamid Sadeghpour SalehModerator quinta-feira, 5 de setembro de 2019 20:17
Todas as Respostas
-
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''
- Sugerido como Resposta Stoyan ChalakovMVP sexta-feira, 16 de agosto de 2019 21:37
- Marcado como Resposta Hamid Sadeghpour SalehModerator quinta-feira, 5 de setembro de 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
\_(ツ)_/
- Editado jrvModerator sexta-feira, 16 de agosto de 2019 22:15