Category filter

Script to install Microsoft Teams PowerShell module

The document helps you with a script to install Microsoft Teams PowerShell module on Windows.

Microsoft Teams is well-known as a platform for collaboration that simplifies communication and teamwork in organizational environments. What if there is a way to customize Microsoft Teams based on organizational requirements using a few simple PowerShell commands? To achieve this seamlessly, PowerShell on Windows devices should have the Microsoft Teams PowerShell module installed. The Microsoft Teams PowerShell Module contains the commands to manage and customize Microsoft Teams environments. Using Hexnode’s Execute Custom Script action, IT administrators can deploy the following script to a fleet of Windows devices in the organization to install the Microsoft Teams PowerShell module.

Disclaimer:

  • The Microsoft Teams PowerShell module requires a Windows device with PowerShell 5.1 or higher.
  • The sample scripts provided below are adapted from third-party open-source sites.

Install Microsoft Teams PowerShell module

The following script installs the Microsoft Teams PowerShell module, which contains the commands for optimizing and customizing the Teams application using PowerShell.

The above script first checks the PowerShellGet command module on the device using the ‘Get-Module’ cmdlet. The PowerShellGet module is a package management module for PowerShell, offering cmdlets such as Install-Module, Uninstall-Module, Find-Module, etc., which help in the installation, removal, and discovery of PowerShell modules. This step serves as a prerequisite for later installing the Microsoft Teams PowerShell module.

Following the installation of the PowerShellGet command module, the script proceeds to install the Microsoft Teams PowerShell module using the ‘Install-Module’ cmdlet. After installation, it imports all the cmdlets that the Microsoft Teams PowerShell module supports, these cmdlets help in managing and customizing the Microsoft Teams application.

Lastly, the script verifies the successful installation of the module by checking the list of installed modules using the ‘Get-Module’ cmdlet. Upon confirmation, it displays the message “Microsoft Teams PowerShell module installed successfully.”

Uninstall Microsoft Teams PowerShell module

The following script checks if the Microsoft Teams PowerShell module is installed on the device using the ‘Get-Module’ cmdlet. If the module is installed, the script proceeds to uninstall it using the “Uninstall-Module” cmdlet.

Upon successful uninstallation of the module, the script produces the message “Microsoft Teams PowerShell module has been successfully uninstalled” as output. Otherwise, it reads an error message stating, “Microsoft Teams PowerShell module is not installed.”

What happens at the device end?

Once the script is deployed, it will install the Microsoft Teams PowerShell module into PowerShell. This can be verified by executing the command “Get-Module -Name MicrosoftTeams –ListAvailable” in the PowerShell.

Initiate a script to install Microsoft Teams PowerShell module and verify the installation from the device's PowerShell
The following are a few example PowerShell cmdlets that can be used to customize and manage the Microsoft Teams application on Windows devices using PowerShell.

  1. Connection Management:
    • Connect-MicrosoftTeams: Connects the user to the Microsoft Teams.
    • Disconnect-MicrosoftTeams: Disconnects a user from the Microsoft Teams.
  2. Teams Management:
    • New-Team: Create a new team.
    • Set-Team: Modify settings of an existing team.
    • Get-Team: Retrieve information about a team.
  3. User and Membership Management:
    • Add-TeamUser: Add users to a team.
    • Remove-TeamUser: Remove users from a team.
  4. Channels Management:
    • New-TeamChannel: Adds a new channel to the team.
    • Remove-TeamChannel: Deletes a channel.
    • Set-TeamChannel: Updates existing channels.
    • Add-TeamChannelUser: Adds a new user to a channel.
    • Remove-TeamChannelUser: Removes a user from a channel.
Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository