Manage OFFICE 365 groups by powershell

OFFICE 365 Poweshell
Share

When you’re working with Exchange online, sometimes it annoying you, cuz each time you need to log in in browser, finding menu with office 365 groups, find the group in search that you need to modify , add user to it.

Stop doing monkey job! Let’s create powershell module which allows us to manage groups in a simple way.

Connect to Exchange

First, let’s create a Function, to connect Exchange online, for accessing PowerShell cmdlets which is exist at this module.  Open PowerShell ISE and type that code:

Now, highlight all code and type F8. Now you can call that function just typing Exchange:

Connect to Exchange

Don’t pay attention to these errors, it’s ok. But if you want to discover more information about this, go to: Connect Exchange

Create functions

Well, now the commands in the module are available to us and we can proceed to creating a function for deleting and adding users.

For adding and removing users from groups Exchange online have two commands:

These two commands have three mandatory parameters:

  • -Identity – provides the name of our Office 365 group
  • -LinkType – provide the Office 365 Group property
  • -Links – it is mail address of our user which we want add to group

In my functions I will use Active Directory module.  The reason is that LinkType Member, return to us members of groups in format: “Name” and “Surname”, but for convenience, in our command, we just want to use only mail address of user. And our Active Directory module beautifully solves that problem.


I have added comments to all the commands in the function, and I think you will have no problems with understanding what is going on, especially if you are new to Powershell :

So, after that, with some changes add another function, which remove user from group, it’s not difficult 😀 :

Creating a module

To create module we should do a several things :

  • Save our three functions in one file with .psm1 extension
  • Create folder in C:\Windows\System32\WindowsPowerShell\v1.0\Modules with name similar to our .psm1 file
  • Import our module to powershell

So, when this things are done, try to import our module ( my module named Office365Groups) with following command :

After that, try to watch all commands in our module :

I have recived that :

Our functions

Now, you can use this function as usual, and it works cool 😀 :

We done it 🙂

Takechico

Author: Takechico

Leave a Reply