-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteams.ps1
47 lines (43 loc) · 1.94 KB
/
teams.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#Check if the necessary module are installed.
if( Get-Module -ListAvailable -Name MicrosoftTeams) {
#Write-Host "Module already installed."
}
else {
#Install module as non-priviliged user.
#Checks if the user is in the administrator group. Warns and stops if the user is not.
#via https://danielengberg.com/check-if-powershell-script-is-running-as-administrator/
try {
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "Installing module as non-priviliegd user."
Install-Module -Name MicrosoftTeams -Scope CurrentUser -ErrorAction Stop #install the module without privilieges.
}
#If administrator
else {
Write-Host "Installing module as administrator."
Install-Module -Name MicrosoftTeams
}
}
catch {
Write-Host "Unable to install the required module MicrosoftTeams"
}
}
#finally {
# Write-Host "Unable to install the required module MicrosoftTeam."
#}
#Uncomment one of the two lines below.
#$accountId = "[email protected]" #Set the accountId, so you don't have to type it every time.
$accountId = Read-Host -Prompt 'The e-mail used to connect to Microsoft Teams' #Ask for account ID.
while (!($accountId)) {
$accountId = Read-Host -Prompt 'The e-mail used to connect to Microsoft Teams'
}
try { #Try to connect to Teams using the provided account id.
Write-Host "Connecting to Teams"
Connect-MicrosoftTeams -AccountId $accountId -ErrorAction Stop #Get pop-up to log in of the user to be handled.
}
catch {
Write-Host "Unable to log in to Teams."
break
}
Write-Host "The user" $accountId "belongs to the following Teams:"
Get-Team -User $accountId #https://docs.microsoft.com/sv-se/powershell/module/teams/get-team?view=teams-ps#examples
Disconnect-MicrosoftTeams