Solved

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

Posted on 2014-03-21
2
699 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
2 Comments
 
LVL 77

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 18

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now