My first question on this forum so hopefully I am doing this right. I have written a script based off of a bit of code I found on this site but it is not producing what I need and I am not sure why. The original code is as follows:
$Mailbox=get-Mailbox xxxx@company.com
$DN=$mailbox.DistinguishedName
$Filter = "Members -like ""$DN"""
Get-DistributionGroup -ResultSize Unlimited -Filter $Filter
This produced the output of a list of distribution lists the user was a member of with 4 columns, Name, DisplayName, GroupType, PrimarySmtpAddress. This works great. I added to this to build a tool where you enter in the users email address but now the output looks like all the properties of the Distribution Lists the user is a member of. Here is my complete code:
Import-Module MSOnline
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/PowerShell -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession -allowclobber $Session
Connect-MsolService -Credential $LiveCred
cd c:\scripts
Write-Host "This tool displays the Distrbution lists a user is a member of"
$User = Read-Host -Prompt 'email address you would like to find the distribution lists of'
$Mailbox=get-Mailbox "$User"
$DN=$mailbox.DistinguishedName
$Filter = "Members -like ""$DN"""
Get-DistributionGroup -ResultSize Unlimited -Filter $Filter