Showing posts with label teams. Show all posts
Showing posts with label teams. Show all posts

Wednesday, 18 August 2021

Microsoft Teams - Add Members from Active Directory Group to Team

Teams may often need to be populated with the members of an existing Active Directory security or distribution group. You can use the powershell commands below to easily do this.

Firstly, we need to get the members of our Active Directory group - and pipe the result to the get-aduser cmdlet so we can include the mail property as this is the identifying field we need to use to add users to Teams.

$grpmembers = Get-ADGroupMember -identity | Get-ADUser -properties mail

We will then enable connect to Microsoft Teams to enable the cmdlets, cycle through the list of members and add them to the team. Make sure you update the $teamgrpid to be the unique group ID for the team you wish to add the users to.

Connect-MicrosoftTeams

$teamgrpid = "123456"

foreach ($grpmember in $grpmembers)
    {
    Add-TeamUser -groupid $teamgrpid -user $($grpmember.mail) -role user
    }

You can change the role variable from user to member if you wish to add the users as members instead.


Monday, 16 August 2021

Microsoft Teams - Assign Teams Policies to Users with Powershell

Policies can be created within Microsoft Teams to manage permissions and restrictions on sets of users. In a school environment for example, you may wish to prevent the ability of students to call other users directly, but allow it for staff.

There are four (4) different types of policies that can be configured/applied to users in Teams;

  1. Calling Policies
  2. Meeting Policies
  3. Channels Policies
  4. Messaging Policies
The policies can be created/configured within the Teams web admin interface.

Calling Policies are configured under Voice > Calling Policies
Meeting Policies are configured under Meetings > Meeting Policies
Channels Policies are configured under Teams > Teams Policies
Messaging Policies are configured under Messaging Policies

Once they're created and configured, they can be applied to users via powershell which can be quicker than doing it manually via the web admin interface - especially if you need to apply it to a large batch of users.

The cmdlet we'll be using for this is New-CsBatchPolicyAssignmentOperation

Be sure to update the PolicyName and Identity arguments to match your policy and user

Apply Teams Calling Policy to Users

New-CSBatchPolicyAssignmentOperation -PolicyType TeamsCallingPolicy -PolicyName "Name" -identity "user@domain.com"

Apply Teams Meeting Policy to Users

New-CSBatchPolicyAssignmentOperation -PolicyType TeamsMeetingPolicy -PolicyName "Name" -identity "user@domain.com"

Apply Teams Channel Policy to Users

New-CSBatchPolicyAssignmentOperation -PolicyType TeamsChannelsPolicy -PolicyName "Name" -identity "user@domain.com"

Apply teams Messaging Policy to Users

New-CSBatchPolicyAssignmentOperation -PolicyType TeamsMessagingPolicy -PolicyName "Name" -identity "user@domain.com"

Checking

You can then check what policies are applied to a user by using the cmdlet below

Get-CsUserPolicyAssignment -identity "user@domain.com" 

This command will return a table displaying all the different policies that are applied to the user specified

Friday, 13 August 2021

Microsoft Teams - Add Additional Team Owner using Powershell

When a user is added to a Microsoft Team, they are added as either a "member" or an "owner". Adding them as an "owner" gives them additional privileges/rights within the team - such as being able to add other members, delete chat messages etc.

If you add a user to a team using the "add-teamuser" powershell cmdlet, it will by default add them as a member. You can use a switch within the command to add them as an owner instead.

Here's an example;

add-teamuser -groupid "abc123" -user "user@domain.com" -role owner

As you can see, the "-role owner" switch is what adds them as an owner to the team, instead of adding them as a member.

If the "-role" switch isn't specified, the user will be added as a member by default. You can alternatively include the "-role" switch and specify "member" as well - like the example below

add-teamuser -groupid "abc123" -user "user@domain.com" -role member

This could be useful if you're using some kind of loop and want to add some users as members and some as owners and have the owner/member specified in a variable.

Thursday, 12 August 2021

Microsoft Teams - Copy Users Team Memberships to Another User

Microsoft Teams doesn't have any easy facility to export all the teams a particular user is a member of which can be useful if you want to copy the team memberships from one user to another.

Thankfully there is a way to do it though - since Microsoft Teams are actually O365 groups behind the scenes, we can utilise some O365 powershell cmdlet magic to accomplish this.

First, we need to connect to our O365 environment then import the session so we can access the cmdlets

$ex = New-PSSession -ConfigurationName Microsoft.Exchange -Credential user@domain.com -ConnectionUri https://outlook.office365.com/powershell -Authentication basic -AllowRedirection

import-pssession $ex

Next, let's get a list of all groups of the user we want to copy from - ie. the source user (be sure to adjust the source user variable to use your own target users email address)

$sourceuser = "user1@domain.com"

$Office365GroupsMember = Get-UnifiedGroup | where { (Get-UnifiedGroupLinks $_.Alias -LinkType Members | foreach {$_.primarysmtpaddress}) -contains $sourceuser}


You can then look at the $Office365GroupsMember variable to see a list of all the O365 groups that the source user is a member of

If you have a mixture of O365 groups AND MSTeams and want to isolate the MS Teams - you can filter the results further by using the command beloww

$o365teamsgroups = $office365GroupsMember | where {$_.serviceendpointuris -like "*MicrosoftTeams*"}

Now that we have our list of Teams, we can go through the list and add our target user to each team. But to do this we need the unique Group ID for each team which is included in the script below. Be sure to update the $targetuser variable with the email address of the user you wish to add to the groups.

Connect-MicrosoftTeams
$targetuser = "user2@domain.com"

foreach ($o365team in $o365teamgroups)
    {
    $teamprops = get-team -displayname $($o365team.displayname)
    write-host "Adding $targetuser to $($teamprops.displayname) team"
    add-teamuser -groupid $($teamprops) -user $targetuser
    }

Wednesday, 11 August 2021

Microsoft Teams - How to Archive Teams using Powershell

Microsoft Teams has a great feature that allows users (and administrators) to archive teams instead of deleting them when they are no longer required. This can be convenient as archived teams are no longer visible to users, but can easily be re-activated (or unarchived) if they, or their contents are required in the future - which isn't possible if you delete a team.

To archive a team, use the command below

Connect-MicrosoftTeams

Set-TeamArchivedState -groupid "teamgroupidnumber123" -Archived:$true

Be sure to update the groupid with the unique groupid for the team you wish to archive. If you don't know what the groupid is, run the cmdlet below

Get-Team -displayname "Team Name"

The GroupID will be displayed in the matching results

After the team is archived you can still view it through the Teams Admin Console

Tuesday, 10 August 2021

Microsoft Teams - Get Team ID/Group ID using Powershell

Many Microsoft Teams commands for powershell require you to specify the group id for a team so the script knows which one of your teams you wish to work on. The Group ID/Team ID is a unique string of letters and numbers which is why it's commonly used to ensure only one team would ever be targeted by a command.

Use the command(s) below to get the group id for one, or all of your teams.

Connect-MicrosoftTeams

get-team -displayname "Test Class"

You should get a response with the GroupID shown like in the example below;


Simple, right? What if I wanted to get the properties for all of my teams? Try the command below

get-team

You can even store the groupid in a variable so it's easier to reference in subsequent commands. In this example, we'll store the properties in the $teamprops variable;

$teamprops = get-team -displayname "Test Class"

You can then use the $teamprops.groupid property in another command - for example;

add-teamuser -groupid $teamprops.groupid -user "user@domain.com"

Monday, 9 August 2021

Microsoft Teams - Add Members to Private Channel using Powershell

If you have a large number of members you need to add to a private channel in teams, you may wish to use powershell to do so as it can be much faster than manually adding users via the Teams app, or web management interface.

Note that you will need to install the preview/prerelease version of the Microsoft Teams powershell module to get access to the cmdlet that we're using here (refer to my separate blog post on how to do this)

Add-TeamChannelUser -GroupID "abc123456789" -Displayname "privatechannelname" -user "user@domain.com"

Be sure to update the Group ID with the unique Group ID of your target team - and the displayname should match the displayname of the private channel you wish to add the user to.

Note that adding users via this cmdlet can cause them to not show in the actual team for some time (in my experience 15-30 mins) so you may need to allow some time before checking/confirming they appear in the channel user list

Sunday, 8 August 2021

Microsoft Teams - Install Preview/Prerelease Powershell Module

Microsoft Teams has a preview/prerelease version of their powershell module available which has some commands that aren't contained in the general/public release.

If you wish to install the prerelease module, you can use the command below to do so

Install-Module -Name MicrosoftTeams -AllowPrerelease -force

You may need to restart your powershell session and import the module again to get the required cmdlets.

If you get an error saying the 'allowprerelease' argument isn't recognized, then run the below commands ot update the PackageManagement and PowershellGet modules

Install-Module -Name PackageManagement -Repository PSGallery -Force
Install-Module -Name PowerShellGet -Repository PSGallery -Force

Restart your powershell session then run the install-module command again and it should complete successfully.

Friday, 6 August 2021

Microsoft Teams - teamchanneluser cmdlet is not recognized

Microsoft Teams features some commands (cmdlets) that are not readily available in the public/general release version of the Microsoft Teams powershell module. Some of these commands are;

get-teamchanneluser

add-teamchanneluser

If you attempt to run these commands, you'll get an error message like the one below;

get-teamchanneluser : The term 'get-teamchanneluser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:1 char:1

To fix the problem you will need to install the preview release of the Microsoft Teams powershell module. You can check the release version numbers from the website below

https://www.powershellgallery.com/packages/MicrosoftTeams/2.0.0

To install the preview release version, make note of the version number then run the command below

Install-Module -Name MicrosoftTeams -AllowPrerelease

To fix the problem you need to force an update of a couple of Powershell modules - namely PowershellGet and PackageManagement. 

Install-Module : A parameter cannot be found that matches parameter name 'AllowPrerelease'.

At line:1 char:37

Run the commands below from an elevanted powershell command prompt;

Install-Module -Name PowerShellGet -Repository PSGallery -Force
Install-Module -Name PackageManagement -Repository PSGallery -Force

Exit/close your Powershell window/session then re-open and run the install-module command again - it should now complete successfully

You can confirm what version is installed by running the commands

import-module "MicrosoftTeams"

get-module

Look for the version number for the "MicrosoftTeams" module

Thursday, 5 August 2021

Microsoft Teams - The term is not recognized as the name of a cmdlet..

If you get an error message like the one below when attempting to issue commands like "connect-microsoftteams" - it's because you haven't got the MS Teams cmdlets installed

Connect-MicrosoftTeams : The term 'Connect-MicrosoftTeams' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:1 char:1

To install the Microsoft Teams Powershell cmdlets, enter the command below. Make sure you run this from an elevated/administrator powershell prompt

install-module -name MicrosoftTeams -force

If you don't run it as administrator, you'll get a message like this;

install-module : Administrator rights are required to install modules in 'C:\Program Files\WindowsPowerShell\Modules'. Log on to the computer with an account that has Administrator rights, and then try again, or install 

'C:\Users\username\Documents\WindowsPowerShell\Modules' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).

The installation may take a minute or two to complete, you can confirm the module has been installed by running the following command

import-module "MicrosofTeams"

Then run the command

get-module

A list of available modules will be displayed which should include MicrosoftTeams like the screenshot below

get-module command output showing MicrosoftTeams module available


Wednesday, 4 August 2021

Microsoft Teams - Powershell Administration Commands

 Microsoft Teams has a powershell module available that allows you to perform just about all Teams management tasks using a script. This is very convenient for bulk operations, like creating lots of teams and keeping team memberships up to date - especially since the Teams web admin interface can be quite slow and cumbersome.

Here's a quick guide on some of the most common commands and uses

Install Microsoft Teams Powershell Module

Use the command below to install the Microsoft Teams powershell cmdlets

install-module -name MicrosoftTeams -force

Create a Team

I like to create new teams by using a variable ($newteam) - this makes additional tasks easier since you can reference the unique group ID for the new team directly from the $newteam variable.

$newteam = new-team -displayname "Test Team" -mailnickname "Test-Team" -owner "user@domain.com"

Update the properties for the display name, mailnickname (can't have spaces) and the team owner

Add a User/Member to a Team

If you've created the team like I have above and used a variable like $newteam, you can then use the properties for this variable for other tasks like this

add-teamuser -groupid $newteam.groupid -user "user@domain.com"

Add an additional Owner to a Team

add-teamuser -groupid $newteam.groupid -user "user@domain.com" -role owner

Remove User/Member from a Team

remove-teamuser -groupid $newteam.groupid -user "user@domain.com"