Skip to content

Commit

Permalink
Remove Email param (#3)
Browse files Browse the repository at this point in the history
* 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
luketainton authored Mar 24, 2020
1 parent bfb9301 commit fa5f0fe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
36 changes: 23 additions & 13 deletions Import-TeamsUsers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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
}
}
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

0 comments on commit fa5f0fe

Please sign in to comment.