5 min read
Tip #3: Utilizing external config data in PowerShell (1/4)
Tobias & Aleksandar's tip #3:
The two very well-known PowerShell experts have teamed up to share their best and most...
Here are some very helpful cmdlets (and corresponding explanations) for all Microsoft Teams administrators. How many of Damian's top ten did you already know?
Using PowerShell to manage Microsoft Teams can be a boon to administrators in Microsoft 365 and just like Exchange PowerShell, Teams PowerShell has a slew of cmldets available to administrators. The purpose of this article is to take what is available to us and take a look at some of the top 10 ways to use Microsoft Teams PowerShell. Let's dive right in.
A common onboarding task is to give a user a license to the features that they need access to. For this section we'll briefly go through the process using Microsoft Graph PowerShell and while this process can still be performed with the MSOnline PowerShell module, Microsoft is deprecating this module over the next year.
For a detailed look at this, take a look at a previous blog post on the ScriptRunner blog which can be found here.
Teams are, of course, the key component of the Microsoft Teams experience and as such, knowing how to create them with PowerShell can also be a useful skill especially if you create many teams with similar settings.
Team creation with PowerShell does not require a lot of options, in fact we can create a team using just a Display Name:
New-Team -DisplayName 'Marketing Campaign – Big Corp, Inc.'
The New-Team cmdlet has other options, like providing a description:
New-Team -DisplayName 'Project Rebuild' -Description 'First project of 2024 (HR)'
Or perhaps turning on one feature for a Team like Search:
New-Team -DisplayName 'New Test Group' -ShowInTeamsSearchAndSuggestions $False
When creating Teams, keep in mind that if a feature is not set upon creation, most if not all settings, can be modified in post with the Set-Team cmdlet.
After we've created our Teams, we can then add Teams Channels to subdivide or organize what each Team needs. For example, we have a Sales Team now and under this Team we need to create channels for each sales drive that the company holds. A consulting firm may have a Team per client and then a Teams Channel for each project they have for that client in order to segregate communications and sharing of content.
New-TeamChannel -GroupId 933fe926-555a-4832-87d1-8f700736e003 -DisplayName 'Project 007'
New-TeamChannel -GroupId cfdba387-1319-4f6b-a883-8700046f07e7 -DisplayName 'Internal Sales'
Note that we need the Group ID in order to create the Teams Channel in that Team.
As alluded to before, Teams that we’ve created previously can also be modified to either meet new needs or possibly create a standard configuration. These changes can be made with the Set-Team cmdlet. For example, if we want to change options that Team members have available to them in a Chanel, like Stickers and Memes or mentions:
Set-Team -GroupId d36f235f-d30e-4460-98a2-5728b906fbfd -GiphyContentRating Strict -AllowStickersAndMemes $False
Get-Team -DisplayName 'Marketing' |
Set-Team -AllowTeamMentions $False
Or perhaps we want to allow Channel updates:
Set-Team -GroupId cfdba387-1319-4f6b-a883-8700046f07e7 -AllowCreateUpdateChannels $True
Get-Team -DisplayName 'HR Department' |
Set-Team -AllowGuestCreateUpdateChannels $False
Turn off Group Search:
Set-Team -GroupId cfdba387-1319-4f6b-a883-8700046f07e7 -ShowInTeamsSearchAndSuggestions $False
Change some group information like Display Name and Description:
Set-TeamChannel -GroupId cfdba387-1319-4f6b-a883-8700046f07e7 -CurrentDisplayName 'Internal Sales' -Description 'Sales Channel'
Or archive a group:
Set-TeamArchivedState -GroupId 9ee34e55-60d6-49cf-8a64-1bc1454d7ee4 -Archived:$True
In addition to the Teams and Channels, PowerShell can manage the global policies that affect all Teams, Users or perhaps meeting settings. By modifying these settings we can control the usage of Teams in an environment and perhaps place Teams into compliance with various corporate policies.
For example we can turn on Transcriptions perhaps the RnD department so that they can take advantage of this feature for their meetings, but have it disabled in other policies:
New-CsTeamsMeetingPolicy -Identity RnDPolicy -AllowTranscription $True
Then we have settings for user admission or breakout room creations:
New-CsTeamsMeetingPolicy -Identity 'MarketingPolicy' -AutoAdmittedUsers 'Everyone' -AllowBreakoutRooms $False
Once a policy is listed and available, we can apply the policy to users:
Grant-CsTeamsMeetingPolicy -Identity 'Jsmith' -PolicyName 'ITDeptMeetings'
Or if policy settings become defunct or are no longer needed, we can remove them:
Remove-CsTeamsMeetingPolicy 'RnDPolicy'
And just like Teams, we can modify a policy once it is created and change settings that may meet some new standard:
Set-CsTeamsMeetingPolicy -Identity 'ITPolicy' -AllowBreakoutRooms $False
Set-CsTeamsMeetingPolicy -Identity 'SalesPolicy' -AllowMeetNow $True
What would Teams be without users? Well, not much actually. So with PowerShell, we can also add users to Microsoft Teams to make sure users have access to the Teams they need in their clients. With the below sample code, we can use a source CSV file and then add members to Teams based on their department:
# Add Teams members
$CSV = Import-CSV 'TeamsUsers.csv'
Foreach ($MsolUser in $CSV) {
$Department = $MsolUser.Department
$Email = $MsolUser.PrimarySMTPAddress
If ($Department -eq 'Marketing') {Add-TeamUser -GroupId $MarketingTeam.GroupId -User $Email}
If ($Department -eq 'Sales') {Add-TeamUser -GroupId $SalesTeam.GroupId -User $Email}
If ($Department -eq 'IT') {Add-TeamUser -GroupId $ITTeam.GroupId -User $Email}
If ($Department -eq 'Management') {Add-TeamUser -GroupId $ManagementTeam.GroupId -User $Email}
}
Assigning roles to those who need to support Microsoft Teams is another important task as we can make sure that the least privilege is used and that these users can perform their tasks. It is important to note that while these role assignments could be done with the MSOnline PowerShell module, this module is being deprecated and should not be used for production work. In the below examples, make sure to connect to Microsoft Graph PowerShell first, with the appropriate permissions.
First, we can list roles for Microsoft Teams:
Get-MgDirectoryRoleTemplate |
Where-Object DisplayName -like Teams*
Next, we have a role addition sample where we add a member to a role, like Teams Communications Support Engineer which first requires identifying the role:
Get-MgDirectoryRole |
Where-Object DisplayName -eq 'Teams Communications Support Engineer'
Then we retrieve the Role’s Id value:
$RoleID = (Get-MgDirectoryRole |
Where-Object DisplayName -eq 'Teams Communications Support Engineer').Id
We then store User data in a variable:
$UserId = (Get-MgUser -UserId damian@practicalPowerShell.com).Id
Finally adding the user to Role group:
New-MgDirectoryRoleMemberByRef -DirectoryRoleId $TeamsAdminRoleId -BodyParameter @{"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$($UserId)"}
Holidays are important in Teams because they provide for different functionality during certain dates or times of the year. When a Holiday is created and assigned, Teams can provide alternate messages or even routing for callers. A common use is to put them in place when the company is closed for business. Let’s walk through some sample code for handling Holidays in Teams:
List current Holidays:
Get-CsOnlineSchedule
Get-CsOnlineSchedule |
Where-Object {$_.Type -eq 'Fixed'}
Create new Holiday:
$Date = New-CsOnlineDateTimeRange -Start '1/12/2020 0:00' -End '1/12/2020 23:45'
New-CsOnlineSchedule -Name 'Employee Day' -DateTimeRanges $Date -FixedSchedule
Change an existing Holiday:
$Schedule = Get-CsOnlineSchedule 93ce710a-f0b6-4c77-80eb-45c73228aa8b
$Schedule.Name = 'New Years Party'
Set-CsOnlineSchedule -Instance $Schedule
Remove existing Holiday:
Remove-CsOnlineSchedule -Id 15f9c478-89a3-4052-9b1b-50eb87e769cf
Auditing IT operations is an important task and can be a necessary task for regulations, audits and other compliance related matters. PowerShell excels at this type of task where potentially large sets of data are involved and filtering is needed. Thus auditing Microsoft Teams events if one of the top ten for Teams PowerShell. In order to audit Teams events, we need to connect to Exchange Online PowerShell (v3) as this is where the Unified Audit log resides.
Teams Events – stored in the Unified Audit Log:
# Past 48 hours
$EndDate = Get-Date
$StartDate = $EndDate.AddDays(-2)
All Teams events:
Search-UnifiedAuditLog -StartDate $StartDate -EndDate $EndDate -RecordType MicrosoftTeams
Teams channels added:
Search-UnifiedAuditLog -StartDate $StartDate -EndDate $EndDate -RecordType MicrosoftTeams -Operations ChannelAdded
Sensitivity Label changes:
Search-UnifiedAuditLog -StartDate $StartDate -EndDate $EndDate -RecordType MicrosoftTeams -Operations SensitivityLabelChanged
Teams are deleted:
Search-UnifiedAuditLog -StartDate $StartDate -EndDate $EndDate -RecordType MicrosoftTeams -Operations TeamDeleted
For Reference – Teams activities
While creating and managing Teams are important tasks, organizations also tend to create too many Teams and in other instances organizations work hard to clear excess Teams on a periodic basis. As such, Teams cleanup is an important task and can be completed with the Remove-Team* set of cmdlets. Below are some sample usages of these cmdlets:
Remove Existing Microsoft Team:
Remove-Team -GroupID '933fe926-555a-4832-87d1-8f700736e003'
Remove Existing Microsoft Team Channel:
Remove-TeamChannel -GroupId cfdba387-1319-4f6b-a883-8700046f07e7 -DisplayName 'Internal Sales'
Remove Existing Microsoft Team User:
Remove-TeamUser -GroupID '933fe926-555a-4832-87d1-8f700736e003' -User <UPN>
As we can see from the Top Ten ways to use PowerShell for Microsoft Teams there are quite a few tasks that we can automate or make easier. From creating Teams, Changing Teams settings to logging and more, PowerShell provides administrators with a programmatic way to manage their environment. With time and practice, the above cmdlets and chores could be automated which would then allow administrators to pass tasks off to other teammates or perhaps do some other projects that have been waiting for a while. The key takeaway is that Microsoft has vested a lot of time and energy into PowerShell and this top ten only scratches the proverbial surface with much more to learn.
Managing Teams can be pretty time consuming. Have you ever wondered how you could optimize and reduce the arising workload?
The PowerShell module for Microsoft Teams is your key: it allows you to standardize and automate many repetitive tasks.
For example:
This webinar is aimed at administrators, IT and DevOps professionals, PowerShell developers and IT managers.
Click here for the webinar recording!
Sep 4, 2024 by Dr. Tobias Weltner and Aleksandar Nikolić
The two very well-known PowerShell experts have teamed up to share their best and most...
Sep 4, 2024 by Aleksandar Nikolić and Dr. Tobias Weltner
The two very well-known PowerShell experts have teamed up to share their best and most...
Sep 4, 2024 by Dr. Tobias Weltner and Aleksandar Nikolić
The two very well-known PowerShell experts have teamed up to share their best and most...
Damian Scoles is a ten-time Microsoft MVP specializing in Exchange, Office 365 and PowerShell who has 25 years of IT industry experience. He is based in the Chicago area and started out managing Exchange 5.5 and Windows NT. Over the years he has worked with Office 365 since BPOS and his experience has grown to include Azure AD, Security and Compliance Admin Centers, and Exchange Online. His community outreach includes contributing to TechNet forums, creating PowerShell scripts that can be found on his blogs, writing in-depth PowerShell / Office365 / Exchange blog articles, tweeting, and creating PowerShell videos on YouTube. He has written five PowerShell books and is also actively working on the book "Microsoft 365 Security for IT Pros".