Solved

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

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

Accepted Solution

by:
arnold earned 500 total points
Comment Utility
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
Comment Utility
$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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Resolve DNS query failed errors for Exchange
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now