For those of us that work a lot with cloud data migration projects, one of the challenges that at least I end up having is to create random data to migrate, that being to test a new migration workload or endpoint, to do a proof of concept or even to troubleshoot a specific issue.
This blog post is focused specifically in adding data to Microsoft Teams, so if for any reason, stated above or not, you need to populate your Microsoft Teams environment, keep reading.
And of course if you’re considering to migrate Microsoft Teams you should go to the BitTitan website and read more about it. We (have an awesome tool that you should definitely use to migrate Teams and if you reach out to me I can get you some help testing it, after you create your test environment with the help of this blog post!
What we will provide in this blog post is a script, authored by Ash Karczag and co-authored by me, that will leverage both PowerShell and the Graph API (yep that’s how awesome the script is), to create and populate a bunch of stuff in your Teams environment, in your Office 365 test tenant.
Note: This script wasn’t designed to be executed in production tenants, since all it creates is based on random names (i.e Team names, Channel names, etc) and it doesn’t have error handling or logging.
What will the script create?
The following actions will be executed by the script, to create objects in Office 365:
- Create 2 users
- Create 10 Teams
- Create 5 team public channels, per Team
- Publish 5 conversations in each channel of each Team
- Upload 5 files to the SharePoint document library of each Team
Which SDK modules or API’s do you need to configure?
The script will leverage multiple SDK’s, for multiple different reasons that include read or create objects and the Microsoft Teams Graph API will be used to create the conversations and upload the files. So in summary, you need:
- Microsoft Azure MSOL Module to connect to your Office 365 tenant (if you don’t have it installed, run “Install-Module MSOnline”)
- Microsoft Teams PowerShell (if you don’t have it installed, run “Install-Module -name MicrosoftTeams”)
- Microsoft Teams Graph API (instructions below on how to set it up in your tenant)
How to configure the Microsoft Teams Graph API authentication
The script requires Migration Teams Graph API access, which is done via OAuth2 authentication. The Graph API will be used to create conversations and to upload the files.
To configure the authentication, follow the steps below:
- Go to portal.azure.com, sign in with global admin
- Select Azure Active Directory
- Select App Registrations
- Select + New Registration
- Enter a name for the application, for example “Microsoft Graph Native App”
- Select “accounts in this organizational directory only”
- Under Redirect URI, select the drop down and choose “Public client/native” and enter “https://redirecturi.com/”
- Select “Register”
- Make a note of your Application (client) ID, and your Directory (tenant) ID
- Under Manage, select “API Permissions”
- Click + Add Permission
- In the Request API Permissions blade, select “Microsoft Graph”
- Select “Delegated Permissions”
- Type “Group” in the Search
- Under the “Group” drop down, select “Group.ReadWrite.All”
- Select “Add Permissions”
- You will get a warning message that says “Permissions have changed, please wait a few minutes and then grant admin consent. Users and/or admins will have to consent even if they have already done so previously.”
- Click “Grant admin consent for <tenant>”
- Wait for permissions to finish propagating, you’ll see a green check-mark if it was successful
- Under Manage, select Certificates & Secrets
- Select “+ New client secret”
- Give the secret a name that indicates its purpose (ex. PowerShell automation secret)
- Under Expires, select Never
- Copy the secret value. YOU WILL NOT SEE THIS SECRET AGAIN AFTER THIS
- Now you have the Client ID, Tenant ID, and Secret to authenticate to Graph using PowerShell
Once the authentication is configured and you have your secret key, you can proceed to executing the script.
How do I get the script
How to execute the script
So now lets go over the steps to execute the script. I am going to number them, just so it’s easier for you to follow:
- Open PowerShell – It is recommended that you open it as an Administrator, since the script will try and set the execution policy to RemoteSigned
- Browse to the .ps1 file location and execute the following
.\Populate_Teams_Data.ps1 -AdminUser "<AdminUsername>" -AdminPass "<AdminPass>" -License "<LicenseSkuID>" -tenantId "<DirectoryID>" -clientId "<AppID>" -ClientSecret "<ClientSecret>"
The values above should be the following values:
- Admin User – your Office 365 Global admin
- Admin Pass – the password for the GA
- License – the license AccountSkuId that you want to apply to the newly created users (Note: Connect to the MSOnline module and run the Get-MsolAccountSku cmdlet in case you don’t know what the value is)
- TenantId – value that you obtained in step 9 of the section above (Directory)
- ClientId – value that you obtained in step 9 of the section above (Application)
- Secret – value that you obtained in step 24 of the section above
The script will describe you the steps that is taking, during its execution, such as:
- Creating the users and the teams
- Adding users to Teams
- Creating channels per team
- Creating usable data in your teams
Additional notes about the script
The following should be considered when executing the script:
- This script was designed and created to be ran against empty tenants. It’s ok if you have users or are using other workloads, but do not run this in a production tenant, since the script was not designed for that.
- The script can be executed multiple times, although it was created for single execution. It will check if Teams and Channels need to be created, but it will try and create users always, unless the user already exists. Have that in mind if you choose to run the script multiple times, to create more usable data.
- The script only creates small files in the Teams. If you want to do a migration test with a large volume of files, you’ll have to upload them manually.
- The script leverages the Graph API, which is the optimal way to create messages and upload files into the Teams, but it’s also a Beta API, so sometimes you might see random timeouts.
We welcome all feedback you might have. Enjoy!