Remove Email param (#3)

* Remove Email param

Signed-off-by: Luke Tainton <luke@tainton.uk>

* Clean up vars as soon as possible

Signed-off-by: Luke Tainton <luke@tainton.uk>
This commit was merged in pull request #3.
This commit is contained in:
2020-03-24 20:00:10 +00:00
committed by GitHub
parent bfb9301aef
commit fa5f0fe8bc
2 changed files with 29 additions and 18 deletions

View File

@@ -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 "user@domain.com" -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
}
}