-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove Email param Signed-off-by: Luke Tainton <[email protected]> * Clean up vars as soon as possible Signed-off-by: Luke Tainton <[email protected]>
- Loading branch information
1 parent
bfb9301
commit fa5f0fe
Showing
2 changed files
with
29 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,16 @@ Function Import-TeamsUsers { | |
.DESCRIPTION | ||
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. | ||
It has one required parameter: -File. | ||
.PARAMETER File | ||
The path to the CSV file that contains your users. Can either be an absolute path or relative path. | ||
.EXAMPLE | ||
Import-TeamsUsers -Email "[email protected]" -File "users.csv" | ||
Import-TeamsUsers -File "users.csv" | ||
#> | ||
|
||
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")] | ||
[string]$File | ||
) | ||
|
@@ -33,7 +28,7 @@ Function Import-TeamsUsers { | |
##### CHECK MODULE IS INSTALLED AND IMPORTED ##### | ||
if (Get-Module -ListAvailable -Name MicrosoftTeams) { | ||
Import-Module -Name MicrosoftTeams | ||
Connect-MicrosoftTeams | ||
$Email = (Connect-MicrosoftTeams -Verbose:$false).Account | ||
} else { | ||
Write-Host -ForegroundColor Red "Module MicrosoftTeams doesn't exist. Please run 'Install-Module -Name MicrosoftTeams' and retry." | ||
Exit | ||
|
@@ -42,8 +37,22 @@ Function Import-TeamsUsers { | |
|
||
Process { | ||
##### GET USER'S TEAMS ##### | ||
Get-Team -User $Email | Select-Object -Property GroupId, DisplayName | Format-Table -AutoSize | ||
$GroupId = Read-Host -Prompt "Paste the GroupId of the desired group" | ||
Clear-Host | ||
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 ##### | ||
$global:UsersAdded = 0; | ||
|
@@ -60,16 +69,17 @@ Function Import-TeamsUsers { | |
} Catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] { | ||
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 { | ||
Write-Host -ForegroundColor Red "Aborting." | ||
Exit | ||
} | ||
} | ||
|
||
End { | ||
Write-Host -ForegroundColor Green "$global:UsersAdded users added successfully." | ||
@('UserCount', 'UsersAdded', 'Consent', 'Users', 'GroupId') | ForEach-Object {Clear-Variable -Name $_} | ||
Disconnect-MicrosoftTeams | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,13 @@ This script runs via PowerShell. If you're on Windows, you'll already have this. | |
|
||
# Running the script | ||
1. Download the repository to your PC. | ||
2. Create a CSV file in the format `email,role`. You can copy the template if required. | ||
3. Change directory to where you downloaded the repository and import the Import-TeamsUsers module (`Import-Module ./Import-TeamsUsers.psm1`). | ||
4. Run `Import-TeamsUsers -Email <EMAIL> -File <FILE>`. | ||
2. Create a CSV file in the format `email,role`. The first line must be the headers `email,role`. You can copy the template if required. | ||
3. Open PowerShell and change directory (`cd`) to the directory where you downloaded the repository. | ||
3. Import the module (`Import-Module ./Import-TeamsUsers.psm1`). | ||
4. Run `Import-TeamsUsers -File <FILE>`. | ||
|
||
# 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:[email protected]?subject=I%20need%20help%20running%20Import-TeamsUsers). | ||
If you require assistance running the script, see the help by executing `Get-Help Import-TeamsUsers` (requires importing the module first - see steps 3 and 4 above). If you still need help, please [send me an email](mailto:[email protected]?subject=I%20need%20help%20running%20Import-TeamsUsers). | ||
|
||
# Issues? Want a new feature? | ||
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! | ||
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 has the same problem or suggestion, and open an issue if one doesn't already exist. If you can implement a fix or feature request, please file a pull request! |