Member-of cmdlet

Few out suggested me to use Get-ADGroupMember but really looking a cmdlet specific to exchange  , I need to write a script to fetch out member-of property for set of mail enabled users for record sake prior to migration . Please sugg
August 26th, 2015 7:17am

i guess we have to use AD cmds to pull memberof property. Please refer the below links further.

http://stackoverflow.com/questions/5072996/how-to-get-all-groups-that-a-user-is-a-member-of

http://www.techtalkz.com/microsoft-windows-powershell/417715-get-group-membership-user.html#post1668928

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 7:39am

First, install the AD PowerShell module on your Exchange server or wherever you are running the Exchange Management Shell from. You can do this as below:

Install-WindowsFeature RSAT-AD-PowerShell

Then run the below script in an elevated PowerShell window as the CSV output path is the C drive root.        

Import-Module ActiveDirectory

$mailboxes = Get-Mailbox -ResultSize Unlimited

$CSV = @()
foreach ($mailbox in $mailboxes)
    {
        $MemberOfDNs = (Get-ADUser $mailbox.SamAccountName -Properties MemberOf).MemberOf
        $MemberOf = @()
        foreach($MemberOfDN in $MemberOfDNs)
            {
                $MemberOf += (Get-ADGroup $MemberOfDN).Name
            }

        $CSVLine = New-Object System.Object
        $CSVLine | Add-Member -Type NoteProperty -Name DisplayName -Value $mailbox.DisplayName
        $CSVLine | Add-Member -Type NoteProperty -Name SamAccountName -Value $mailbox.SamAccountName
        $CSVLine | Add-Member -Type NoteProperty -Name MemberOf -Value ($MemberOf -join "; ")
        $CSV += $CSVLine
    }

$CSV | Export-Csv -NoTypeInformation C:\Report.csv

Let me know if that helps you out.

Thanks.

August 26th, 2015 10:33am

member-of is basically Active Directory related attribute or more related to AD and not Exchange so you would need to use AD related PowerShell cmdlets to fetch the values. 

I am sure script Mark gave would be helpful for you...

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 6:51pm

Hi,

I have a script to share with you. This script will tell you what distribution groups a user is a member of.

$User = read-host -Prompt "Enter Username"

$user_dn = (get-mailbox $user).distinguishedname

"User " + $User + " is a member of the following groups:"

foreach ($group in get-distributiongroup -resultsize unlimited){

if ((get-distributiongroupmember $group.identity | select -expand distinguishedname) -contains $user_dn){$group.name}

}

Best Regards.
August 26th, 2015 11:07pm

Thanks all for your valuable time and support, I've written a script referring you guys per my requirement. Here you go :)

https://gallery.technet.microsoft.com/exchange/Export-Member-of-in-multi-9cf4b315

Free Windows Admin Tool Kit Click here and download it now
September 6th, 2015 3:45pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics