\n Hi, and welcome to the PowerShell forum! \n\n\nDon’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask! \n\n\nUse a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which. \n\n\nDon’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…\n <\/blockquote>\n<\/aside>\n\n <\/p>","upvoteCount":0,"datePublished":"2018-07-11T21:35:05.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Sorry forgot about that, updated<\/p>","upvoteCount":0,"datePublished":"2018-07-11T21:37:48.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/7","author":{"@type":"Person","name":"gorgeittech","url":"https://community.spiceworks.com/u/gorgeittech"}},{"@type":"Answer","text":"
Ok, and where do you want to put the phone number in therE? in the out-file?<\/p>\n
Maybe you should rather build a custom object, that would be cleaner…<\/p>","upvoteCount":0,"datePublished":"2018-07-11T21:39:02.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/8","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
Yes I want it in the outfile, and I thought about the custom object, just didn’t know how to pull the information, still learning<\/p>","upvoteCount":0,"datePublished":"2018-07-11T21:41:15.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/9","author":{"@type":"Person","name":"gorgeittech","url":"https://community.spiceworks.com/u/gorgeittech"}},{"@type":"Answer","text":"
I haven’t tested it, but this is the idea<\/p>\n
$objDistributionGroups = Get-DistributionGroup -ResultSize Unlimited\n$OutputFile = \"$env:userprofile\\desktop\\export.csv\"\n\nForeach ($objDistributionGroup in $objDistributionGroups) { \n write-verbose \"Processing $($objDistributionGroup.DisplayName)...\" -verbose\n\n #Get members of this group \n $objDGMembers = Get-DistributionGroupMember $objDistributionGroup.PrimarySmtpAddress\n write-verbose \"Found $($objDGMembers.Count) members...\" -Verbose\n\n #Iterate through each member \n Foreach ($objMember in $objDGMembers) { \n $data = [PSCustomObject]@{\n GroupDisplayName = $objDistributionGroup.DisplayName\n GroupPrimarySMTPAddress = $objDistributionGroup.PrimarySMTPAddress\n UserDisplayName = $objMember.DisplayName\n Phone = $objMember.Phone\n MobilePhone = (get-msoluser $objMember.PrimarySMTPAddress).MobilePhone\n UserPrimarySMTPAddress = $objMember.PrimarySMTPAddress\n RecipientType = $objMember.RecipientType\n }\n\n $data | export-csv $OutputFile -Append -NoTypeInformation\n\n write-host \"`t$data\"\n }\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-11T21:57:55.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"will give this a try and see what I come up with, thanks so much for the help<\/p>","upvoteCount":0,"datePublished":"2018-07-11T22:00:09.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/11","author":{"@type":"Person","name":"gorgeittech","url":"https://community.spiceworks.com/u/gorgeittech"}},{"@type":"Answer","text":"
why you running get-distribution listt? if you need contact run<\/p>\n
Get-MailContact|select DisplayName,Mobile\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-12T01:51:26.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/12","author":{"@type":"Person","name":"jitensh","url":"https://community.spiceworks.com/u/jitensh"}},{"@type":"Answer","text":"I’m OP’s co-worker and have been tasked with taking over this script. The original request from our client is to pull a list of users (along with names, email address, primary and mobile phone numbers) in distribution lists from their office 365 environment. However, their DLs are populated with a mix of users in their AD structure and contact records they created for people external to the company. The script OP posted gets us 90% of the data but the command doesn’t support the mobile phone field from what we could find. OP is more advanced in powershell usage than I am but due to circumstances beyond my control they are no longer available to help with this.<\/p>\n
Is there a clean way to pull the data the client is requesting given that the DLs are both AD users and contact records?<\/p>\n
Thanks in advance<\/p>","upvoteCount":0,"datePublished":"2018-07-17T20:56:53.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/13","author":{"@type":"Person","name":"davenoel","url":"https://community.spiceworks.com/u/davenoel"}},{"@type":"Answer","text":"
First, lets find out what kinds of objects Get-DistributionGroupMember is returning and what their properties are.<\/p>\n
\n# Choosea distribution list that has both users and contacts\n\n$typeGroups = Get-DistributionGroupMember -Identity \"Ditribution list\"|Group-Object $_.getType()\n\nforeach ($typeGroup in $typeGroups){\n\n $typeGroup.Name\n\n $typeGroup.Group|Get-Member -MemberType Property\n\n}\n\n<\/code><\/pre>\nThis will let us know what type of objects we are working with and what properties are being included. Run it and report back.<\/p>","upvoteCount":0,"datePublished":"2018-07-18T13:12:34.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/14","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}},{"@type":"Answer","text":"
produces the following error:<\/p>\n
You cannot call a method on a null-valued expression.\nAt line:1 char:1\n+ $typeGroups = Get-DistributionGroupMember -Identity \"Ditribution list ...\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n + CategoryInfo : InvalidOperation: (:) [], RuntimeException\n + FullyQualifiedErrorId : InvokeMethodOnNull\n\n<\/code><\/pre>\nThank you for your help.<\/p>","upvoteCount":0,"datePublished":"2018-07-24T15:28:02.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/15","author":{"@type":"Person","name":"davenoel","url":"https://community.spiceworks.com/u/davenoel"}},{"@type":"Answer","text":"
You need to replace “Ditribution list”<\/em> with the name of an actual distribution list that contains both users and contacts, as I explained in the comment.<\/p>","upvoteCount":0,"datePublished":"2018-07-25T11:37:25.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/16","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}},{"@type":"Answer","text":"I launched a powershell session, ran connect-msolservice, entered the admin credentials and ran the script you provided and entered the actual distro list display name that I’m looking for and it returns the same error.<\/p>","upvoteCount":0,"datePublished":"2018-07-26T20:45:13.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/17","author":{"@type":"Person","name":"davenoel","url":"https://community.spiceworks.com/u/davenoel"}},{"@type":"Answer","text":"
There is no way I can debug this remotely. Try each step in the pipeline until you find the error.<\/p>\n
Start with<\/p>\n
Get-DistributionGroupMember -Identity \"Whatever your group is called\"\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2018-07-27T11:52:15.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/18","author":{"@type":"Person","name":"tulioarends","url":"https://community.spiceworks.com/u/tulioarends"}},{"@type":"Answer","text":"Is there another set of tools I need to install to make it work? I have the Azure AD tools installed. “get-DistributionGroupMember is not recognized as the name of a cmdlet, function, script file, or operable program.”<\/p>","upvoteCount":0,"datePublished":"2018-07-27T13:10:26.000Z","url":"https://community.spiceworks.com/t/office-365-field-data/661482/19","author":{"@type":"Person","name":"davenoel","url":"https://community.spiceworks.com/u/davenoel"}}]}}
Neally
(Neally)
July 11, 2018, 9:35pm
6
If you post code, please use the ‘Insert Code’ button. Please and thank you!
Hi, and welcome to the PowerShell forum!
Don’t apologize for being a “noob” or “newbie” or “n00b.” There’s just no need – nobody will think you’re stupid, and the forums are all about asking questions. Just ask!
Use a descriptive subject. Don’t say “Need help” or “PowerShell Help”, actually summarize what the problem is. It helps the rest of us keep track of which problem is which.
Don’t post massive scripts. We’re all volunteers and we don’t have time to read all that, nor will we copy…