Unicode support & different delimiters #11
@@ -12,7 +12,7 @@
|
|||||||
# RootModule = ''
|
# RootModule = ''
|
||||||
|
|
||||||
# Version number of this module.
|
# Version number of this module.
|
||||||
ModuleVersion = '2.1.2'
|
ModuleVersion = '2.2.0'
|
||||||
|
|
||||||
# Supported PSEditions
|
# Supported PSEditions
|
||||||
# CompatiblePSEditions = @()
|
# CompatiblePSEditions = @()
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ Function Import-TeamsUsers {
|
|||||||
.PARAMETER Create
|
.PARAMETER Create
|
||||||
If specified, create a new Group first, then add the users from the CSV file.
|
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
|
.EXAMPLE
|
||||||
Import-TeamsUsers -File "users.csv"
|
Import-TeamsUsers -File "users.csv"
|
||||||
|
|
||||||
@@ -24,23 +30,37 @@ Function Import-TeamsUsers {
|
|||||||
[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")]
|
[parameter(Mandatory=$false, position=2, ParameterSetName='Params', HelpMessage="Create new Teams group")]
|
||||||
[switch]$Create
|
[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 {
|
Begin {
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
##### IMPORT CSV FILE #####
|
##### IMPORT CSV FILE #####
|
||||||
Try {
|
Try {
|
||||||
$Users = Import-CSV $File
|
$ImportCmd = "Import-CSV $File"
|
||||||
|
If ($Delimiter) { $ImportCmd = $ImportCmd + " -Delimiter $Delimiter" }
|
||||||
|
If ($Encoding) { $ImportCmd = $ImportCmd + " -Encoding $Encoding" }
|
||||||
|
$Users = Invoke-Expression $ImportCmd
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host -ForegroundColor Red "$File is not a valid CSV file."
|
Write-Host -ForegroundColor Red "$File is not a valid CSV file."
|
||||||
|
Exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
##### 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
|
try {
|
||||||
$Email = (Connect-MicrosoftTeams -Verbose:$false).Account
|
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 {
|
} 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
|
||||||
|
|||||||
Reference in New Issue
Block a user