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:
@@ -6,21 +6,16 @@ Function Import-TeamsUsers {
|
|||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Import-TeamsUsers is a Powershell function that will enrol users from a CSV file into a given Microsoft Teams group.
|
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.
|
It has one required parameter: -File.
|
||||||
|
|
||||||
.PARAMETER Email
|
|
||||||
Your Office 365 email address. This is used to list your teams.
|
|
||||||
|
|
||||||
.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.
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Import-TeamsUsers -Email "user@domain.com" -File "users.csv"
|
Import-TeamsUsers -File "users.csv"
|
||||||
#>
|
#>
|
||||||
|
|
||||||
Param(
|
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")]
|
[parameter(Mandatory=$true, position=1, ParameterSetName='Params', HelpMessage="Specify CSV file")]
|
||||||
[string]$File
|
[string]$File
|
||||||
)
|
)
|
||||||
@@ -33,7 +28,7 @@ Function Import-TeamsUsers {
|
|||||||
##### CHECK MODULE IS INSTALLED AND IMPORTED #####
|
##### CHECK MODULE IS INSTALLED AND IMPORTED #####
|
||||||
if (Get-Module -ListAvailable -Name MicrosoftTeams) {
|
if (Get-Module -ListAvailable -Name MicrosoftTeams) {
|
||||||
Import-Module -Name MicrosoftTeams
|
Import-Module -Name MicrosoftTeams
|
||||||
Connect-MicrosoftTeams
|
$Email = (Connect-MicrosoftTeams -Verbose:$false).Account
|
||||||
} else {
|
} else {
|
||||||
Write-Host -ForegroundColor Red "Module MicrosoftTeams doesn't exist. Please run 'Install-Module -Name MicrosoftTeams' and retry."
|
Write-Host -ForegroundColor Red "Module MicrosoftTeams doesn't exist. Please run 'Install-Module -Name MicrosoftTeams' and retry."
|
||||||
Exit
|
Exit
|
||||||
@@ -42,8 +37,22 @@ Function Import-TeamsUsers {
|
|||||||
|
|
||||||
Process {
|
Process {
|
||||||
##### GET USER'S TEAMS #####
|
##### GET USER'S TEAMS #####
|
||||||
Get-Team -User $Email | Select-Object -Property GroupId, DisplayName | Format-Table -AutoSize
|
Clear-Host
|
||||||
$GroupId = Read-Host -Prompt "Paste the GroupId of the desired group"
|
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 #####
|
##### ENROL USERS #####
|
||||||
$global:UsersAdded = 0;
|
$global:UsersAdded = 0;
|
||||||
@@ -60,16 +69,17 @@ Function Import-TeamsUsers {
|
|||||||
} Catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] {
|
} Catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] {
|
||||||
Write-Host -ForegroundColor Red "Error adding user $User with role $Role"
|
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 {
|
} Else {
|
||||||
Write-Host -ForegroundColor Red "Aborting."
|
Write-Host -ForegroundColor Red "Aborting."
|
||||||
Exit
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
End {
|
End {
|
||||||
Write-Host -ForegroundColor Green "$global:UsersAdded users added successfully."
|
@('UserCount', 'UsersAdded', 'Consent', 'Users', 'GroupId') | ForEach-Object {Clear-Variable -Name $_}
|
||||||
Disconnect-MicrosoftTeams
|
Disconnect-MicrosoftTeams
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -9,12 +9,13 @@ This script runs via PowerShell. If you're on Windows, you'll already have this.
|
|||||||
|
|
||||||
# Running the script
|
# Running the script
|
||||||
1. Download the repository to your PC.
|
1. Download the repository to your PC.
|
||||||
2. Create a CSV file in the format `email,role`. You can copy the template if required.
|
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. Change directory to where you downloaded the repository and import the Import-TeamsUsers module (`Import-Module ./Import-TeamsUsers.psm1`).
|
3. Open PowerShell and change directory (`cd`) to the directory where you downloaded the repository.
|
||||||
4. Run `Import-TeamsUsers -Email <EMAIL> -File <FILE>`.
|
3. Import the module (`Import-Module ./Import-TeamsUsers.psm1`).
|
||||||
|
4. Run `Import-TeamsUsers -File <FILE>`.
|
||||||
|
|
||||||
# Need help?
|
# 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:luke@tainton.uk?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:luke@tainton.uk?subject=I%20need%20help%20running%20Import-TeamsUsers).
|
||||||
|
|
||||||
# Issues? Want a new feature?
|
# 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!
|
||||||
|
|||||||
Reference in New Issue
Block a user