Need help writing office365 powershell script

Copper Contributor
I'm trying to write a script that will create a mail contact and enter name and email address, then create a distribution group and enter email, then add created mail contact to the group. Any help would be appreciated?
1 Reply

What kind of help are you looking for? From what I gather from your description, you simply need three cmdlets, and their use is very straightforward. You don't even need to add any input logic as PowerShell will ask you for the missing information. So something like this would work:

 

$contact = New-MailContact

$DG = New-DistributionGroup

Add-DistributionGroupMember $dg.PrimarySmtpAddress -Member $contact.ExternalEmailAddress

 

Now of course you might want to add some additional infromation, input controls if you think they are necessary, error handling and so on. There are multiple examples available online on how to do that, look them up and start playing with the cmdlets, that's the best way to learn PS.