Nieuw Office 365 bericht: How to bulk add users to a MS Team

Sometimes you want to bulk add users to a team. There is an interface to add users but you have to add them one by one:

In some cases you want to add a lot of users. For example you are a teacher and wants to add your students before the start of your classes. Doing this one by one will be very time consuming. So I created a PowerShell script to do this. You don’t need any special permissions to run the script. You only have to be the owner of the team.

First we need a few things:

The teams group Id

Every team (or group) has an unique Id. You can find this by getting the link of the team and search for the groupId parameter in the url:

The url is something like this:

https://ift.tt/2Rsa323?groupId=e000eb72-0948-4a89-b1ad-ad708beebbb4&tenantId=1a5763a5-a000-486d-8bed-162db29f5e62 (fake url for security reasons ? )

You need to copy the id: e000eb72-0948-4a89-b1ad-ad708beebbb4

Next we need a list with email addresses that you want to add. Store them in a plain text file (input.txt)

The script will use Microsoft Teams and AzureAD commands so make sure you have installed them by running these commands in PowerShell once (open the PowerShell terminal with elevated permissions):

Install-Module -Name MicrosoftTeams 
Install-Module -Name AzureAD

Now we can start, run the following script. You’ll have to enter your credentials a few times.

#change the path to the text file:
$emailaddresses=Get-Content -Path "C:\Users\demouser\input.txt"

#change the ID parameter here
$teamId="GROUP - ID"

# -----------------------------------------
# Run this first
# -----------------------------------------
Set-ExecutionPolicy RemoteSigned
# -----------------------------------------

#not working with MFA accounts
#$crendentials=Get-Credential

Connect-MicrosoftTeams #-Credential $crendentials
Connect-AzureAD #-Credential $crendentials

$team=Get-Team -GroupId $teamId

$groupMembers=(Get-AzureADGroupMember -ObjectId $teamId -All $true | select UserPrincipalName)

#Write-Host $groupMembers

Write-Host "Check current users" -ForegroundColor White
for($i=0; $i -lt $groupMembers.length; $i++){
    write-host $groupMembers[$i]

    #check if user is in valid user list
    #if NO, then delete the user from TEAMS

    if($emailaddresses.tolower().Contains($groupMembers[$i].UserPrincipalName.toLower())){
        #Write-Host "user found"
    }
    else{
        Write-Host "user not found: remove from TEAMS" -ForegroundColor Red
        Remove-TeamUser -groupId $teamId -User $groupMembers[$i].UserPrincipalName
    }
}

#add new users
Write-Host "Check user membership" -ForegroundColor White
for($i=0; $i -lt $emailaddresses.length; $i++){
    write-host $emailaddresses[$i]
    $bUserFound=$false
    #check if the user is already in TEAMS
    #if NO, then ADD the user
    for($j=0; $j -lt $groupMembers.length;$j++){
      
        if($groupMembers[$j].UserPrincipalName.toLower() -eq $emailaddresses[$i].ToLower()){
            $bUserFound=$true
            #Write-Host "user found in teams members list" -ForegroundColor Yellow
            break
        }
    }

    if(!$bUserFound){
        Write-Host "adding member to TEAMS" -ForegroundColor Green
        Add-TeamUser -GroupId $teamId -User $emailaddresses[$i]
    }

}

Feel free to use this!

Dit verscheen eerst op SPums.be

Nieuw Office 365 bericht: Populate a Word document with Microsoft Flow

A few weeks ago a client asked to create a workflow that pre-populates a Word document with some data from a SharePoint list. This was my chance to use the new Microsoft Flow action called: Populate a Microsoft Word template.

This action can read a Word document and populate the fields you defined. You can add fields to a Word document via the “Developers tab” in Word. You have to enable this first when you haven’t done this before. If you are not sure how to do this you can check this help page.

For now the Flow action only works when these conditions are met:

  1. Only text controls are allowed (no checkboxes and so)
  2. The file must be on your OneDrive for Business, not on a SharePoint library (I hope this changes real soon!)

So I created a word file with a plain text control and stored it on my OneDrive for Business folder.

Next I created a SharePoint list where the customer added an item for each meeting that was organized. The item contains a text field with the names of the attendees.

The create the Word document I created a Flow that runs for a selected item in that list. In this development example I created an input field to test the flow:

next you need to populate the Word file (I fetch the data from the listitem first to use later in the flow)

To finish I create a new Word file on a SharePoint library:

So in this flow I

  • Populated a Word document with some data from a SharePoint list item
  • Created a file with that content to a SharePoint list

There are still some issues with this Flow action but it looks promising. I hope that soon we can populate other fields (repeating fields??) and the template file can be stored on SharePoint instead of OneDrive for Business.

Dit verscheen eerst op SPums.be

Nieuw Office 365 bericht: Flow for event registration and automated meeting request

Today I had this question from a client:

Can I use Office 365 for event registrations linked to my calendar?

Event registration? Sure. Create an input form with Microsoft Forms! That’s easy. But the client wanted to send the registered users a meeting request. Not just a single meeting request but all users must be added to the existing meeting in his calendar.

First, let’s create the form:
I created a form with some basic fields like name, first name and email.

So for so good. Make sure the form is accessible for anonymous users.

Next, I need to create a workflow that sends the (updated) meeting request to the users:

First I need the Forms trigger “When a new response is submitted”:

Then we need the form entry details. You can use the “Get response details” action. A loop will be created for you:

Select the form id and use the Response Id from the previous step.

Now the “tricky” part. We need to update an existing meeting request in the calender of the user.
First we need the meeting details. Use the “Get event (V2)” action to do this:

First select the calendar in the dropdown. Next we need the ID of the event. This was the part I needed to think ?

How can I find the Id of an event? There is no interface in outlook for this but there is the Office Graph Explorer!
The Office Graph Explorer is an interface on top of the Office 365 API. Build for developers. There is an API to get a list of events and there you can find the ID of a certain event! Cool isn’t it?

First sign in with your Office 365 account to use the Graph with your data. Next check your profile to see if it is working:
You should see your data:

Now use this query: https://ift.tt/1UIfeT8 this will get you a list of all events in your calendar:

In the response preview window you will get a list of events. In that list you can find the Id of each event:

Now we will use that Id in our flow.

Next add the “Update event (V2)” action. With this action you update the properties of a calendar event.

Use the same ID, add the fields that don’t need to be updates. Use the content from the previous step here.
The attendees are behind the “advanced options”. Add the field from the previous step and the email address of the user that he entered in the initial form:

This is the trick that did it!

So, I could answer the question of the client. It is possible to build an event registration (no code) solution based on Office 365!

Dit verscheen eerst op SPums.be