🚀: Version 2.1.0 #5

Merged
luketainton merged 2 commits from createteam into master 2020-05-19 14:44:50 +00:00
2 changed files with 46 additions and 18 deletions

View File

@@ -13,7 +13,7 @@ This module uses PowerShell, which is pre-installed on Windows. If you're not on
jbloggs@example.com,owner jbloggs@example.com,owner
user@example.com,member user@example.com,member
``` ```
1. Run `Import-TeamsUsers -File <FILE>`, where `<FILE>` is the path to the CSV file. 1. Run `Import-TeamsUsers -File <FILE>`, where `<FILE>` is the path to the CSV file. You can add the `-Create` flag if you want to create a new team first.
<details> <details>
<summary>If you can't run non-signed scripts</summary> <summary>If you can't run non-signed scripts</summary>

View File

@@ -10,19 +10,32 @@ Function Import-TeamsUsers {
.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.
.PARAMETER Create
If specified, create a new Group first, then add the users from the CSV file.
.EXAMPLE .EXAMPLE
Import-TeamsUsers -File "users.csv" Import-TeamsUsers -File "users.csv"
.EXAMPLE
Import-TeamsUsers -Create -File "users.csv"
#> #>
Param( Param(
[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,
[parameter(Mandatory=$false, position=2, ParameterSetName='Params', HelpMessage="Create new Teams group")]
[switch]$Create
) )
Begin { Begin {
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
##### IMPORT CSV FILE ##### ##### 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 ##### ##### CHECK MODULE IS INSTALLED AND IMPORTED #####
if (Get-Module -ListAvailable -Name MicrosoftTeams) { if (Get-Module -ListAvailable -Name MicrosoftTeams) {
@@ -35,23 +48,38 @@ Function Import-TeamsUsers {
} }
Process { Process {
##### GET USER'S TEAMS ##### If ($Create) {
Clear-Host ##### CREATE NEW TEAM #####
Write-Host -ForegroundColor Green "Getting your teams - please wait" Clear-Host
$EligibleTeams = @() $NewTeamName = Read-Host -Prompt "Name of the new group"
Get-Team -User $Email -Verbose:$false | ForEach-Object { $NewTeamDesc = Read-Host -Prompt "Group description"
$CTeamId = $_.GroupId $NewTeamPriv = Read-Host -Prompt "P[u]blic or P[r]ivate?"
$CTeamName = $_.DisplayName If ($NewTeamPriv -Eq "u") {
If (Get-TeamUser -GroupId $CTeamId | Select-Object -Property User,Role | Where-Object {$_.User -eq $Email} | Where-Object {$_.Role -eq "owner"}) { $NewTeamVis = "Public"
$EligibleTeams += @{GroupId = $CTeamId; DisplayName = $CTeamName} } Elseif ($NewTeamPriv -Eq "r") {
$NewTeamVis = "Private"
} }
Clear-Variable -Name CTeamId $NewTeam = New-Team -DisplayName $NewTeamName -MailNickName $NewTeamName -Description "Testing team creation from PowerShell" -Visibility $NewTeamVis
Clear-Variable -Name CTeamName $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-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 ##### ##### ENROL USERS #####
$global:UsersAdded = 0; $global:UsersAdded = 0;