Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 412966ec1d | |||
| 99718ae5aa | |||
| b2ea10d113 | |||
| 5b1a4dd1d1 | |||
| 58e5ed94b6 | |||
| fa5f0fe8bc |
38
README.md
38
README.md
@@ -1,20 +1,32 @@
|
|||||||
# Import-TeamsUsers
|
# TeamsUserEnroller
|
||||||
A Powershell script that imports users from a CSV into a Microsoft Teams team.
|
A Powershell module that imports users from a CSV into a Microsoft Teams group.
|
||||||
|
|
||||||
# Setting up your device
|
# Setting up your device
|
||||||
This script runs via PowerShell. If you're on Windows, you'll already have this. If not, please download it from the [releases page](https://github.com/PowerShell/PowerShell/releases). Once you've got PowerShell:
|
This module uses PowerShell, which is pre-installed on Windows. If you're not on Windows, please [download **PowerShell Core**](https://github.com/PowerShell/PowerShell/releases).
|
||||||
1. Open PowerShell as an administrator.
|
1. Open PowerShell as an administrator.
|
||||||
2. Allow remote scripts to execute by running `Set-ExecutionPolicy RemoteSigned`. If you don't do this, the script won't run.
|
1. Install this module by running `Install-Module -Name TeamsUsersEnroller`.
|
||||||
3. Install the Microsoft Teams module. To do this, run `Install-Module -Name MicrosoftTeams`. Accept any prompts that you are given.
|
|
||||||
|
|
||||||
# Running the script
|
# Running the script
|
||||||
1. Download the repository to your PC.
|
1. Create a CSV file containing your users and their desired roles. The first line must be the headers `email,role`, for example:
|
||||||
2. Create a CSV file in the format `email,role`. You can copy the template if required.
|
```csv
|
||||||
3. Change directory to where you downloaded the repository and import the Import-TeamsUsers module (`Import-Module ./Import-TeamsUsers.psm1`).
|
email,role
|
||||||
4. Run `Import-TeamsUsers -Email <EMAIL> -File <FILE>`.
|
jbloggs@example.com,owner
|
||||||
|
user@example.com,member
|
||||||
|
```
|
||||||
|
1. Run `Import-TeamsUsers -File <FILE>`, where `<FILE>` is the path to the CSV file.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>If you can't run non-signed scripts</summary>
|
||||||
|
If your policy requires scripts to be digitally signed, run
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
Set-ExecutionPolicy Bypass -Scope Process
|
||||||
|
```
|
||||||
|
then try running the command again. You may require administrative rights to do change the Execution Policy.
|
||||||
|
</details>
|
||||||
|
|
||||||
# Need help?
|
# Need help?
|
||||||
If you require assistance running the script, see the help by executing `Get-Help Import-TeamsUsers` (requires importing the module first - see step 2 above). If you still need help, please [send me an email](mailto:luke@tainton.uk?subject=I%20need%20help%20running%20Import-TeamsUsers).
|
If you need assistance, please try the following:
|
||||||
|
1. See the help documentation by running `Get-Help Import-TeamsUsers`.
|
||||||
# Issues? Want a new feature?
|
1. Check closed issues [here](https://github.com/luketainton/Import-TeamsUsers/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aclosed).
|
||||||
If you're having problems with the script 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. Open an issue [here](https://github.com/luketainton/Import-TeamsUsers/issues/new).
|
||||||
132
TeamsUserEnroller.psd1
Normal file
132
TeamsUserEnroller.psd1
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
#
|
||||||
|
# Module manifest for module 'TeamsUserEnroller'
|
||||||
|
#
|
||||||
|
# Generated by: Luke Tainton
|
||||||
|
#
|
||||||
|
# Generated on: 21/04/2020
|
||||||
|
#
|
||||||
|
|
||||||
|
@{
|
||||||
|
|
||||||
|
# Script module or binary module file associated with this manifest.
|
||||||
|
# RootModule = ''
|
||||||
|
|
||||||
|
# Version number of this module.
|
||||||
|
ModuleVersion = '2.0.0'
|
||||||
|
|
||||||
|
# Supported PSEditions
|
||||||
|
# CompatiblePSEditions = @()
|
||||||
|
|
||||||
|
# ID used to uniquely identify this module
|
||||||
|
GUID = 'a7b4e6d0-c92e-40df-a238-2b7a131a13a1'
|
||||||
|
|
||||||
|
# Author of this module
|
||||||
|
Author = 'Luke Tainton'
|
||||||
|
|
||||||
|
# Company or vendor of this module
|
||||||
|
CompanyName = 'Luke Tainton'
|
||||||
|
|
||||||
|
# Copyright statement for this module
|
||||||
|
Copyright = '(c) 2020 Luke Tainton. All rights reserved.'
|
||||||
|
|
||||||
|
# Description of the functionality provided by this module
|
||||||
|
Description = 'A Powershell module that will enrol users from a CSV file into a given Microsoft Teams group.'
|
||||||
|
|
||||||
|
# Minimum version of the PowerShell engine required by this module
|
||||||
|
# PowerShellVersion = ''
|
||||||
|
|
||||||
|
# Name of the PowerShell host required by this module
|
||||||
|
# PowerShellHostName = ''
|
||||||
|
|
||||||
|
# Minimum version of the PowerShell host required by this module
|
||||||
|
# PowerShellHostVersion = ''
|
||||||
|
|
||||||
|
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||||
|
# DotNetFrameworkVersion = ''
|
||||||
|
|
||||||
|
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||||
|
# CLRVersion = ''
|
||||||
|
|
||||||
|
# Processor architecture (None, X86, Amd64) required by this module
|
||||||
|
# ProcessorArchitecture = ''
|
||||||
|
|
||||||
|
# Modules that must be imported into the global environment prior to importing this module
|
||||||
|
RequiredModules = @('MicrosoftTeams')
|
||||||
|
|
||||||
|
# Assemblies that must be loaded prior to importing this module
|
||||||
|
# RequiredAssemblies = @()
|
||||||
|
|
||||||
|
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||||
|
# ScriptsToProcess = @()
|
||||||
|
|
||||||
|
# Type files (.ps1xml) to be loaded when importing this module
|
||||||
|
# TypesToProcess = @()
|
||||||
|
|
||||||
|
# Format files (.ps1xml) to be loaded when importing this module
|
||||||
|
# FormatsToProcess = @()
|
||||||
|
|
||||||
|
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||||
|
NestedModules = @('./TeamsUserEnroller.psm1')
|
||||||
|
|
||||||
|
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||||
|
FunctionsToExport = @('Import-TeamsUsers')
|
||||||
|
|
||||||
|
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||||
|
CmdletsToExport = '*'
|
||||||
|
|
||||||
|
# Variables to export from this module
|
||||||
|
VariablesToExport = '*'
|
||||||
|
|
||||||
|
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
|
||||||
|
AliasesToExport = '*'
|
||||||
|
|
||||||
|
# DSC resources to export from this module
|
||||||
|
# DscResourcesToExport = @()
|
||||||
|
|
||||||
|
# List of all modules packaged with this module
|
||||||
|
# ModuleList = @()
|
||||||
|
|
||||||
|
# List of all files packaged with this module
|
||||||
|
FileList = @('./TeamsUserEnroller.psm1')
|
||||||
|
|
||||||
|
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||||
|
PrivateData = @{
|
||||||
|
|
||||||
|
PSData = @{
|
||||||
|
|
||||||
|
# Tags applied to this module. These help with module discovery in online galleries.
|
||||||
|
Tags = @('Teams', 'Skype', 'Office365')
|
||||||
|
|
||||||
|
# A URL to the license for this module.
|
||||||
|
# LicenseUri = ''
|
||||||
|
|
||||||
|
# A URL to the main website for this project.
|
||||||
|
ProjectUri = 'https://github.com/luketainton/TeamsUserEnroller'
|
||||||
|
|
||||||
|
# A URL to an icon representing this module.
|
||||||
|
# IconUri = ''
|
||||||
|
|
||||||
|
# ReleaseNotes of this module
|
||||||
|
ReleaseNotes = 'https://github.com/luketainton/TeamsUserEnroller/releases'
|
||||||
|
|
||||||
|
# Prerelease string of this module
|
||||||
|
# Prerelease = ''
|
||||||
|
|
||||||
|
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
|
||||||
|
RequireLicenseAcceptance = $false
|
||||||
|
|
||||||
|
# External dependent modules of this module
|
||||||
|
# ExternalModuleDependencies = @()
|
||||||
|
|
||||||
|
} # End of PSData hashtable
|
||||||
|
|
||||||
|
} # End of PrivateData hashtable
|
||||||
|
|
||||||
|
# HelpInfo URI of this module
|
||||||
|
# HelpInfoURI = ''
|
||||||
|
|
||||||
|
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||||
|
# DefaultCommandPrefix = ''
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -6,21 +6,15 @@ Function Import-TeamsUsers {
|
|||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Import-TeamsUsers is a Powershell function that will enrol users from a CSV file into a given Microsoft Teams group.
|
Import-TeamsUsers is a Powershell function that will enrol users from a CSV file into a given Microsoft Teams group.
|
||||||
It has two required parameters (switches): -Email and -File.
|
|
||||||
|
|
||||||
.PARAMETER Email
|
|
||||||
Your Office 365 email address. This is used to list your teams.
|
|
||||||
|
|
||||||
.PARAMETER File
|
.PARAMETER File
|
||||||
The path to the CSV file that contains your users. Can either be an absolute path or relative path.
|
The path to the CSV file that contains your users. Can either be an absolute path or relative path.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Import-TeamsUsers -Email "user@domain.com" -File "users.csv"
|
Import-TeamsUsers -File "users.csv"
|
||||||
#>
|
#>
|
||||||
|
|
||||||
Param(
|
Param(
|
||||||
[parameter(Mandatory=$true, position=0, ParameterSetName='Params', HelpMessage="Specify your Office 365 email address")]
|
|
||||||
[string]$Email,
|
|
||||||
[parameter(Mandatory=$true, position=1, ParameterSetName='Params', HelpMessage="Specify CSV file")]
|
[parameter(Mandatory=$true, position=1, ParameterSetName='Params', HelpMessage="Specify CSV file")]
|
||||||
[string]$File
|
[string]$File
|
||||||
)
|
)
|
||||||
@@ -33,7 +27,7 @@ Function Import-TeamsUsers {
|
|||||||
##### CHECK MODULE IS INSTALLED AND IMPORTED #####
|
##### CHECK MODULE IS INSTALLED AND IMPORTED #####
|
||||||
if (Get-Module -ListAvailable -Name MicrosoftTeams) {
|
if (Get-Module -ListAvailable -Name MicrosoftTeams) {
|
||||||
Import-Module -Name MicrosoftTeams
|
Import-Module -Name MicrosoftTeams
|
||||||
Connect-MicrosoftTeams
|
$Email = (Connect-MicrosoftTeams -Verbose:$false).Account
|
||||||
} else {
|
} else {
|
||||||
Write-Host -ForegroundColor Red "Module MicrosoftTeams doesn't exist. Please run 'Install-Module -Name MicrosoftTeams' and retry."
|
Write-Host -ForegroundColor Red "Module MicrosoftTeams doesn't exist. Please run 'Install-Module -Name MicrosoftTeams' and retry."
|
||||||
Exit
|
Exit
|
||||||
@@ -42,8 +36,22 @@ Function Import-TeamsUsers {
|
|||||||
|
|
||||||
Process {
|
Process {
|
||||||
##### GET USER'S TEAMS #####
|
##### GET USER'S TEAMS #####
|
||||||
Get-Team -User $Email | Select-Object -Property GroupId, DisplayName | Format-Table -AutoSize
|
Clear-Host
|
||||||
$GroupId = Read-Host -Prompt "Paste the GroupId of the desired group"
|
Write-Host -ForegroundColor Green "Getting your teams - please wait"
|
||||||
|
$EligibleTeams = @()
|
||||||
|
Get-Team -User $Email -Verbose:$false | ForEach-Object {
|
||||||
|
$CTeamId = $_.GroupId
|
||||||
|
$CTeamName = $_.DisplayName
|
||||||
|
If (Get-TeamUser -GroupId $CTeamId | Select-Object -Property User,Role | Where-Object {$_.User -eq $Email} | Where-Object {$_.Role -eq "owner"}) {
|
||||||
|
$EligibleTeams += @{GroupId = $CTeamId; DisplayName = $CTeamName}
|
||||||
|
}
|
||||||
|
Clear-Variable -Name CTeamId
|
||||||
|
Clear-Variable -Name CTeamName
|
||||||
|
}
|
||||||
|
Clear-Host
|
||||||
|
Write-Host "Teams that you own:"
|
||||||
|
$EligibleTeams | ForEach-Object {[PSCustomObject]$_} | Format-Table 'GroupId', 'DisplayName' -AutoSize
|
||||||
|
$GroupId = Read-Host -Prompt "GroupId of the desired group"
|
||||||
|
|
||||||
##### ENROL USERS #####
|
##### ENROL USERS #####
|
||||||
$global:UsersAdded = 0;
|
$global:UsersAdded = 0;
|
||||||
@@ -60,16 +68,17 @@ Function Import-TeamsUsers {
|
|||||||
} Catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] {
|
} Catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] {
|
||||||
Write-Host -ForegroundColor Red "Error adding user $User with role $Role"
|
Write-Host -ForegroundColor Red "Error adding user $User with role $Role"
|
||||||
}
|
}
|
||||||
|
Clear-Variable -Name User
|
||||||
|
Clear-Variable -Name Role
|
||||||
}
|
}
|
||||||
|
Write-Host -ForegroundColor Green "$global:UsersAdded users added successfully."
|
||||||
} Else {
|
} Else {
|
||||||
Write-Host -ForegroundColor Red "Aborting."
|
Write-Host -ForegroundColor Red "Aborting."
|
||||||
Exit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
End {
|
End {
|
||||||
Write-Host -ForegroundColor Green "$global:UsersAdded users added successfully."
|
@('UserCount', 'UsersAdded', 'Consent', 'Users', 'GroupId') | ForEach-Object {Clear-Variable -Name $_}
|
||||||
Disconnect-MicrosoftTeams
|
Disconnect-MicrosoftTeams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
email,role
|
|
||||||
|
Reference in New Issue
Block a user