Initial commit

Signed-off-by: Luke Tainton <luke@tainton.uk>
This commit is contained in:
2020-02-27 17:26:22 +00:00
parent 3b30f89dd0
commit e8c52cfc0a
3 changed files with 63 additions and 0 deletions

49
Import-TeamsUsers.ps1 Normal file
View File

@@ -0,0 +1,49 @@
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

View File

@@ -1,2 +1,15 @@
# Import-TeamsUsers # Import-TeamsUsers
A Powershell script that imports users from a CSV into a Microsoft Teams team. A Powershell script that imports users from a CSV into a Microsoft Teams team.
# Setup
You'll need to do a few things before you can run the script:
1. Have a CSV file. This needs to be in the format `email,role`. You can copy the template if required.
2. Install the module. Run `Install-Module -Name MicrosoftTeams` in your Powershell terminal.
3. Import the module. Run `Import-Module -Name MicrosoftTeams` in your Powershell terminal.
4. Authenticate to the API. Run `Connect-MicrosoftTeams` in your Powershell terminal.
# How to use
Open `Import-TeamsUsers.ps1` and modify the `$GroupId` and `$File` variables at the bottom, then execute the script from the command line.
# Issues?
If you're having problems or have an idea for a new feature, please check [here](https://github.com/luketainton/Import-TeamsUsers/issues) to see if someone else is having the same problem, and open an issue if one doesn't already exist. If you can implement a fix or feature request, please file a pull request!

1
template.csv Normal file
View File

@@ -0,0 +1 @@
email,role
1 email role