Collect Distribution Group where the user memberof

Below script helps in collecting Distribution Group where the user memberof

################################################################

# Scripting for Office365

################################################################

#Script Written by : Kingson Jebaraj

# ==============================================================================================

# Crendentials and Logon

# ==============================================================================================

Get-PSSession | Remove-PSSession

Get-Module tmp* | Remove-Module

$administrator = “Kingson@de-hackers.com”

$password = Get-Content “C:\Scripts\pass.txt” | ConvertTo-SecureString -AsPlainText -force

$credential = New-Object System.Management.Automation.PSCredential $administrator,$password

$Server= “https://outlook.office365.com/powershell-liveid/”

$session = New-PSSession -Authentication basic -Credential $credential –ConnectionUri $Server -Configuration Microsoft.Exchange -AllowRedirection

Import-PSSession $session

# ==============================================================================================

# Get DL to Which user is member of

# ==============================================================================================

$User = Read-Host “Enter input here”

$user_dn = (Get-Mailbox $user).distinguishedname

Write-Host “Please wait this might take some time to process…..”

“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}

}

 Category: Exchange Office365
About Kingson Jebaraj

<p>Microsoft MVP, Blogger, Owner and Publisher for Cloudexchangers.com, Microsoft TechNet Author, Solution Architect, Former Office365 Technical Lead for Microsoft(Partner) </p> <p>Extensive knowledge and experience in Microsoft Exchange and Cloud Messaging Services and has got more exposure on Messaging environment deployment,migration,designing and other project management activities, I have earned real time experience in handling multi-site distributed critical large environment of messaging system.</p> <p>Been awarded as an MVP (Microsoft Most Valuable Professional) for Office Servers and services from Microsoft for an exceptional real world contribution made through Microsoft forums and other Microsoft communities.</p> <p>Currently working as “Solution Architect” on Private/Public cloud and SaaS environment for Pacific Controls, UAE, Dubai. One of the largest TIER III certified green data center campus in the middle east.</p>

Related articles

Leave a Reply