Solved

Powershell script to compare group membership for various users listed in txt file.

Posted on 2014-03-21
2
719 Views
Last Modified: 2014-05-08
New to powershell.  
Is there a quick script someone can provide?  
Windows 2008 R2 DCS.
I have a list of users in a txt file.  I need to search the list of users in txt file and their group membership to see if there is a common group listed then export to CSV file.  
Any help would be greatly appreciated!
0
Comment
Question by:ITLady45
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 78

Accepted Solution

by:
arnold earned 500 total points
ID: 39946889
There are many examples of scripts that do individual things.
Here is a reference to one that lets you search for a group membership
http://gallery.technet.microsoft.com/scriptcenter/5adf9ad0-1abf-4557-85cd-657da1cc7df4

There is a powershell cmdlet that reads data from a file and iterates through it.
http://technet.microsoft.com/en-us/library/ee692806.aspx


You would need to combine the examples into a single process to achieve your current at the conclusion of which you'll have a .......
0
 
LVL 19

Expert Comment

by:suriyaehnop
ID: 39948285
$Result= @()
$Users = Import-Csv C:\Filename.csv

Foreach ($User in $Users){

$Mailbox = Get-Mailbox -Identity $User
$DL      = Get-DistributionGroup -ResultSize Unlimited | where { (Get-DistributionGroupMember $_ | foreach {$_.PrimarySMTPAddress}) -contains $User.PrimarySMTPAddress}

$Mbx = New-Object System.Object

$Mbx | Add-Member -MemberType NoteProperty -Name Displayname -Value $Mailbox.DisplayName
$Mbx | Add-Member -MemberType NoteProperty -Name DistributionName -Value $DL.Name

$Result +=$Mbx

}

$Result

Open in new window


Your CSV must have a user's PrimarySMTPAddress ad header mean:

Email
user01@contoso.com
user02@contoso.com
..................
.................
..................
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question