Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db150a3973 | |||
| ab72c8c2ba | |||
| 20307da1e3 | |||
| 5bdf885036 | |||
| 9fb651f29d | |||
| 218f6cc3a5 | |||
| aef71bb6c8 | |||
| ead4d470f7 | |||
| c383fb840d | |||
| 1d7e7c71b7 | |||
| cb3d1eb3bd | |||
| 42fdf856b5 | |||
| 6b13a2d1fc | |||
| 2056117ea7 | |||
| 0f8b9dfdea | |||
| eba04be5f3 | |||
| a88fb454fa | |||
| 44a90b2c52 |
9
.github/issue-branch.yml
vendored
Normal file
9
.github/issue-branch.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
mode: auto
|
||||
silent: false
|
||||
branchName: short
|
||||
branches:
|
||||
- label: feature
|
||||
prefix: feature/
|
||||
- label: bug
|
||||
prefix: bug/
|
||||
autoCloseIssue: true
|
||||
14
.github/workflows/autobranch.yml
vendored
Normal file
14
.github/workflows/autobranch.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
on:
|
||||
issues:
|
||||
types: [assigned]
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
create_issue_branch_job:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Create Issue Branch
|
||||
uses: robvanderleek/create-issue-branch@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
14
.github/workflows/sponsors.yml
vendored
Normal file
14
.github/workflows/sponsors.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
name: Label sponsors
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened]
|
||||
issues:
|
||||
types: [opened]
|
||||
jobs:
|
||||
build:
|
||||
name: is-sponsor-label
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: JasonEtco/is-sponsor-label-action@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
19
.github/workflows/stale.yml
vendored
Normal file
19
.github/workflows/stale.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
name: Mark stale issues and pull requests
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/stale@v1
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'This issue has been marked as stale due to inactivity. If this issue is still ongoing, please leave a comment.'
|
||||
stale-pr-message: 'This pull request has been marked as stale due to inactivity. If this PR is still ongoing, please leave a comment.'
|
||||
stale-issue-label: 'status/stale'
|
||||
stale-pr-label: 'status/stale'
|
||||
16
README.md
16
README.md
@@ -4,7 +4,7 @@ A Powershell module that imports users from a CSV into a Microsoft Teams group.
|
||||
# Setting up your device
|
||||
This module uses PowerShell, which is pre-installed on Windows. If you're not on Windows, please [download **PowerShell Core**](https://github.com/PowerShell/PowerShell/releases).
|
||||
1. Open PowerShell as an administrator.
|
||||
1. Install this module by running `Install-Module -Name TeamsUsersEnroller`.
|
||||
1. Install this module by running `Install-Module -Name TeamsUserEnroller`.
|
||||
|
||||
# Running the script
|
||||
1. Create a CSV file containing your users and their desired roles. The first line must be the headers `email,role`, for example:
|
||||
@@ -13,20 +13,20 @@ This module uses PowerShell, which is pre-installed on Windows. If you're not on
|
||||
jbloggs@example.com,owner
|
||||
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>
|
||||
<summary>If you can't run non-signed scripts</summary>
|
||||
If your policy requires scripts to be digitally signed, run
|
||||
### If you can't run non-signed scripts
|
||||
If your policy requires scripts to be digitally signed, run
|
||||
|
||||
```powershell
|
||||
Set-ExecutionPolicy Bypass -Scope Process
|
||||
```
|
||||
then try running the command again. You may require administrative rights to do change the Execution Policy.
|
||||
</details>
|
||||
then try running the command again. You may require administrative rights to change the Execution Policy.
|
||||
|
||||
# Need help?
|
||||
If you need assistance, please try the following:
|
||||
1. See the help documentation by running `Get-Help Import-TeamsUsers`.
|
||||
1. Check closed issues [here](https://github.com/luketainton/Import-TeamsUsers/issues?q=is%3Aissue+sort%3Aupdated-desc+is%3Aclosed).
|
||||
1. Open an issue [here](https://github.com/luketainton/Import-TeamsUsers/issues/new).
|
||||
1. Open an issue [here](https://github.com/luketainton/Import-TeamsUsers/issues/new).
|
||||
|
||||
Alternatively, you can subscribe [here](https://lists.tainton.uk/mailman/listinfo/tue-users_lists.tainton.uk) to receive general announcements, ask questions, and assist other users. You must be subscribed to the list to be able to send email to it (I am working on this!)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# RootModule = ''
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '2.0.0'
|
||||
ModuleVersion = '2.2.1'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
|
||||
@@ -10,24 +10,90 @@ 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.
|
||||
|
||||
.PARAMETER Delimiter
|
||||
If specified, overrides the default CSV delimiter of ','.
|
||||
|
||||
.PARAMETER Encoding
|
||||
If specified, manually sets the encoding of 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,
|
||||
[parameter(Mandatory=$false, position=3, ParameterSetName='Params', HelpMessage="Override default CSV delimiter")]
|
||||
[string]$Delimiter,
|
||||
[parameter(Mandatory=$false, position=4, ParameterSetName='Params', HelpMessage="Manually set CSV encoding")]
|
||||
[string]$Encoding
|
||||
)
|
||||
|
||||
Begin {
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
##### CHECK FOR NEW VERSION #####
|
||||
Try {
|
||||
# Get information from GitHub Releases
|
||||
$releases = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/luketainton/TeamsUserEnroller/releases";
|
||||
$rel = $releases[0];
|
||||
$latest_version = $rel.tag_name -replace 'v', '';
|
||||
$latest_version_changes = $rel.body;
|
||||
|
||||
# Get currently installed version
|
||||
$current_version = (Get-Module TeamsUserEnroller | Select-Object Version).Version;
|
||||
|
||||
# Compare versions and alert user if newer version available
|
||||
if ($current_version -lt $latest_version) {
|
||||
Write-Host -ForegroundColor Yellow "A new version of TeamsUserEnroller has been released!";
|
||||
Write-Host -ForegroundColor Yellow "Latest version: $latest_version";
|
||||
Write-Host -ForegroundColor Yellow "Installed version: $current_version";
|
||||
Write-Host -ForegroundColor Yellow "`n$latest_version_changes";
|
||||
$Consent = Read-Host -Prompt "`nWould you like to update now? [y/N]"
|
||||
If ($Consent -eq "y" -Or $Consent -eq "Y") {
|
||||
Update-Module -Name TeamsUserEnroller -RequiredVersion "2.2.0";
|
||||
$after_update_ver = (Get-Module TeamsUserEnroller | Select-Object Version).Version;
|
||||
if ($after_update_ver -eq $latest_version) {
|
||||
Write-Host -ForegroundColor Green "Update completed.";
|
||||
} Else {
|
||||
Write-Host -ForegroundColor Red "Update failed. Please update manually.";
|
||||
}
|
||||
}
|
||||
}
|
||||
} Catch {
|
||||
Write-Host -ForegroundColor Red "An error occurred while checking for updates. Continuing.";
|
||||
}
|
||||
|
||||
##### IMPORT CSV FILE #####
|
||||
$Users = Import-CSV $File
|
||||
Try {
|
||||
$ImportCmd = "Import-CSV $File"
|
||||
If ($Delimiter) { $ImportCmd = $ImportCmd + " -Delimiter $Delimiter" }
|
||||
If ($Encoding) { $ImportCmd = $ImportCmd + " -Encoding $Encoding" }
|
||||
$Users = Invoke-Expression $ImportCmd
|
||||
} Catch {
|
||||
Write-Host -ForegroundColor Red "$File is not a valid CSV file."
|
||||
Exit
|
||||
}
|
||||
|
||||
|
||||
##### CHECK MODULE IS INSTALLED AND IMPORTED #####
|
||||
if (Get-Module -ListAvailable -Name MicrosoftTeams) {
|
||||
Import-Module -Name MicrosoftTeams
|
||||
$Email = (Connect-MicrosoftTeams -Verbose:$false).Account
|
||||
try {
|
||||
Import-Module -Name MicrosoftTeams
|
||||
$Email = (Connect-MicrosoftTeams -Verbose:$false).Account
|
||||
} Catch {
|
||||
Write-Host -ForegroundColor Red "There was an error during authentication."
|
||||
Write-Host "If you're not on Windows and use Multi-Factor Authentication, please manually pass the MFA check in your browser, then try again."
|
||||
Exit
|
||||
}
|
||||
} else {
|
||||
Write-Host -ForegroundColor Red "Module MicrosoftTeams doesn't exist. Please run 'Install-Module -Name MicrosoftTeams' and retry."
|
||||
Exit
|
||||
@@ -35,23 +101,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"
|
||||
}
|
||||
Clear-Variable -Name CTeamId
|
||||
Clear-Variable -Name CTeamName
|
||||
$NewTeam = New-Team -DisplayName $NewTeamName -MailNickName $NewTeamName -Description $NewTeamDesc -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-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;
|
||||
|
||||
Reference in New Issue
Block a user