Need help writing office365 powershell script

%3CLINGO-SUB%20id%3D%22lingo-sub-1013780%22%20slang%3D%22en-US%22%3ENeed%20help%20writing%20office365%20powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1013780%22%20slang%3D%22en-US%22%3EI'm%20trying%20to%20write%20a%20script%20that%20will%20create%20a%20mail%20contact%20and%20enter%20name%20and%20email%20address%2C%20then%20create%20a%20distribution%20group%20and%20enter%20email%2C%20then%20add%20created%20mail%20contact%20to%20the%20group.%20Any%20help%20would%20be%20appreciated%3F%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1013780%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%20ISE%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1013835%22%20slang%3D%22en-US%22%3ERe%3A%20Need%20help%20writing%20office365%20powershell%20script%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1013835%22%20slang%3D%22en-US%22%3E%3CP%3EWhat%20kind%20of%20help%20are%20you%20looking%20for%3F%20From%20what%20I%20gather%20from%20your%20description%2C%20you%20simply%20need%20three%20cmdlets%2C%20and%20their%20use%20is%20very%20straightforward.%20You%20don't%20even%20need%20to%20add%20any%20input%20logic%20as%20PowerShell%20will%20ask%20you%20for%20the%20missing%20information.%20So%20something%20like%20this%20would%20work%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24contact%20%3D%20New-MailContact%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3E%24DG%20%3D%20New-DistributionGroup%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3EAdd-DistributionGroupMember%20%24dg.PrimarySmtpAddress%20-Member%20%24contact.ExternalEmailAddress%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20style%3D%22background-color%3A%20%23ffffff%3B%22%3ENow%20of%20course%20you%20might%20want%20to%20add%20some%20additional%20infromation%2C%20input%20controls%20if%20you%20think%20they%20are%20necessary%2C%20error%20handling%20and%20so%20on.%20There%20are%20multiple%20examples%20available%20online%20on%20how%20to%20do%20that%2C%20look%20them%20up%20and%20start%20playing%20with%20the%20cmdlets%2C%20that's%20the%20best%20way%20to%20learn%20PS.%3C%2FFONT%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor
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.