Adding/Removing Groups
Adding and removing groups with 365AutomatedLab is as easy as it is for adding and removing users(If you missed part one, check out Getting Started with 365AutomatedLab Part 1) It can add and remove the 4 different groups(Group, Mail Enabled Security, Distribution, and Security) that 365 has from one excel sheet. As of right now it will fill in the Display Name, Primary SMTP, and Description. I’ll be adding more parameters, but wanted to get at least these available. What are some other parameters you want to see first?
Adding Groups
Now the fun part, adding groups with one line of code. But, first we need to have a worksheet named “Groups” with the column headers
- DisplayName
- PrimarySMTP
- Description
- Type
After you have created those, you can input the data that you want in those fields. Remember for type you will use 365Group, 365MailEnabledSecurity, 365Distribution, or 365Security, which will tell 365 what type of group you want created. If you don’t have test data feel free to go to the already premade Excel workbook in the LabSources section in the repository. Below is a quick snapshot of the Excel workbook.
Data all set? Let’s run this little One-Liner to import all these groups into 365!
New-CT365Group -FilePath C:\\Scripts\\LabSources\\365DataEnvironment3.xlsx -UserPrincipalName admin@yourdomainname.onmicrosoft.com -Domain yourdomainname.onmicrosoft.com
Depending on when you last logged in, you’ll have to confirm access twice, once for Exchange Online and once for Graph. If you don’t allow these, the script will look like it froze on you. Trying to save you some of the headaches that I went through!
Your 365 Portal should now look like this
All set! That’s really how easy it is!
Removing Groups
The beauty of this setup, is now you only have to one PowerShell command, and you are all set.
Remove-CT365Group -FilePath C:\\Scripts\\LabSources\\365DataEnvironment3.xlsx -UserPrincipalName admin@yourdomainname.onmicrosoft.com
All done, now all your groups in your Excel workbook are removed!
Summary
Wasn’t it easy? Testing larger data sets will be a breeze or setting up and removing tests. You should never have to test in a production environment, as you can copy those groups to the Excel workbook and import them into your Dev tenant. I hope you found this helpful and makes your life easier as it has mine. If you have any recommendations or questions, please feel free to reach out and/or create a Github Issue.
Leave a Reply