Files
TeamsUserEnroller/Import-TeamsUsers.ps1
Luke Tainton e8c52cfc0a Initial commit
Signed-off-by: Luke Tainton <luke@tainton.uk>
2020-02-27 17:26:22 +00:00

50 lines
1.6 KiB
PowerShell
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function Import-TeamsUsers {
Param(
[parameter(Mandatory=$true,HelpMessage="Specify Group ID")]
$GroupId,
[parameter(Mandatory=$true,HelpMessage="Specify CSV file")]
$File
)
# Import CSV file and required module
$Users = Import-CSV $File
$UserCount = $Users | Measure-Object | Select-Object -expand count
Import-Module -Name MicrosoftTeams
# Check Team exists
Try {
$Team = Get-Team -GroupId $GroupId
If ($Team) {
$TeamName = $Team.DisplayName
Write-Host -ForegroundColor Green "Team $TeamName exists!"
}
} Catch [System.UnauthorizedAccessException] {
# User is not authenticated
Write-Host -ForegroundColor Red "You need to authenticate to Microsoft Teams before continuing. Please run 'Connect-MicrosoftTeams' and try again."
Break
} Catch [System.Net.Http.HttpRequestException] {
# Team does not exist
Write-Host -ForegroundColor Red "Team with ID $GroupId does not exist!"
Break
}
$Consent = Read-Host -Prompt "You are about to add $UserCount users. Are you sure? [y/N]"
If ($Consent -eq "y" -Or $Consent -eq "Y") {
$Users | ForEach-Object {
$User = $_.email
$Role = $_.role
Write-Host "Adding user $User with role $Role"
Add-TeamUser -GroupId $GroupId -Role $Role -User $User -ErrorAction SilentlyContinue
}
} Else {
Write-Host -ForegroundColor Red "Aborting."
}
}
$GroupId = ""
$File = ""
Import-TeamsUsers -GroupId $GroupId -File $File