Skip to content

Commit

Permalink
👌 IMPROVE: Allow creation of new group
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Tainton <luke@tainton.uk>
  • Loading branch information
luketainton committed May 19, 2020
1 parent 42fdf85 commit cb3d1eb
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions TeamsUserEnroller.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,32 @@ Function Import-TeamsUsers {
.PARAMETER File
The path to the CSV file that contains your users. Can either be an absolute path or relative path.
.PARAMETER Create
If specified, create a new Group first, then add the users from the CSV file.
.EXAMPLE
Import-TeamsUsers -File "users.csv"
.EXAMPLE
Import-TeamsUsers -Create -File "users.csv"
#>

Param(
[parameter(Mandatory=$true, position=1, ParameterSetName='Params', HelpMessage="Specify CSV file")]
[string]$File
[string]$File,
[parameter(Mandatory=$false, position=2, ParameterSetName='Params', HelpMessage="Create new Teams group")]
[switch]$Create
)

Begin {
$ErrorActionPreference = 'Stop'
##### IMPORT CSV FILE #####
$Users = Import-CSV $File
Try {
$Users = Import-CSV $File
} Catch {
Write-Host -ForegroundColor Red "$File is not a valid CSV file."
}


##### CHECK MODULE IS INSTALLED AND IMPORTED #####
if (Get-Module -ListAvailable -Name MicrosoftTeams) {
Expand All @@ -35,23 +48,38 @@ Function Import-TeamsUsers {
}

Process {
##### GET USER'S TEAMS #####
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}
If ($Create) {
##### CREATE NEW TEAM #####
Clear-Host
$NewTeamName = Read-Host -Prompt "Name of the new group"
$NewTeamDesc = Read-Host -Prompt "Group description"
$NewTeamPriv = Read-Host -Prompt "P[u]blic or P[r]ivate?"
If ($NewTeamPriv -Eq "u") {
$NewTeamVis = "Public"
} Elseif ($NewTeamPriv -Eq "r") {
$NewTeamVis = "Private"
}
$NewTeam = New-Team -DisplayName $NewTeamName -MailNickName $NewTeamName -Description "Testing team creation from PowerShell" -Visibility $NewTeamVis
$GroupId = $NewTeam.GroupId
} Else {
##### GET USER'S TEAMS #####
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-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"
}
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 Down

0 comments on commit cb3d1eb

Please sign in to comment.