Solved

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

Posted on 2014-03-21
2
707 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerShell .lastLogonTimestamp off 11 27
Powershell replace german characters in string 12 29
set-aduser powershell command issue 2 30
Locating a GPO setting 3 31
A procedure for exporting installed hotfix details of remote computers using powershell
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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…

803 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