1

I got a list of 150+ users and I want to know which group they have membership for? I just started using PS. I can query for 1 user, but not for a list of users. Would like to know exact command??? I got :

(get-aduser -identity "username" -properties memberof |select-object memberof).memberof > c:\temp\ss.csv

1 Answer 1

1

Read your user list into an array and check if your AD users are contained in that array:

$userlist = Get-Content 'C:\your\userlist.txt'

Get-ADUser -Filter '*' -Properties memberof | Where-Object {
  $userlist -contains $_.SamAccountName
} | ForEach-Object {
  $username = $_
  $groups = $_ | Select-Object -Expand memberof |
            ForEach-Object { (Get-ADGroup $_).Name }
  "{0}: {1}" -f $username, ($groups -join ', ')
} | Out-File 'c:\temp\ss.csv'

Replace SamAccountName as appropriate if the user list doesn't contain the account names of the users.

Sign up to request clarification or add additional context in comments.

8 Comments

Sorry to ask, we save this script as .vbs?
Hi Ansgar, your script is returning error. Can you check n post it again? Thx.
@Svi It's PowerShell, not VBScript, so it should be saved as .ps1. And the code works just fine. If you're getting an error, please update your question with the code you used and the error it produced.
Hi, my userlist.txt file structure is like: accountname zachem adelto
my script is saved as grpname.ps1 and code in it is : $userlist = Get-Content 'C:\temp\del\userlist.txt' Get-ADUser -Filter 'accountname' -Properties memberof | ? { $userlist -contains $_.AccountName } | select -Expand memberof > 'c:\temp\del\ss.csv' it's not giving error, but not giving any output too ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.