{"id":471,"date":"2024-08-10T11:35:26","date_gmt":"2024-08-10T04:35:26","guid":{"rendered":"https:\/\/nbvps.anhtuanlqd.com\/?p=471"},"modified":"2025-01-09T10:02:46","modified_gmt":"2025-01-09T03:02:46","slug":"add-multiple-teams-members","status":"publish","type":"post","link":"https:\/\/nbvps.anhtuanlqd.com\/?p=471","title":{"rendered":"Add multiple Teams Members"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Y\u00eau c\u1ea7u:<\/h2>\n\n\n\n<p>File students.csv v\u1edbi header: Email (1 c\u1ed9t duy nh\u1ea5t)<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>M\u1edf powershell as administrator<\/p>\n\n\n\n<p>Ch\u1ea1y l\u1ec7nh sau \u0111\u1ec3 m\u1edf Policy Execution: <\/p>\n\n\n\n<p><strong>Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass<br><\/strong><br>T\u1ea1o file students.csv v\u1edbi 1 c\u1ed9t, header: Email<\/p>\n\n\n\n<p>t\u1ea1o file<strong> teams.ps1 <\/strong>v\u1edbi n\u1ed9i dung nh\u01b0 sau (c\u1ea7n thay teamId cho ph\u00f9 h\u1ee3p, m\u1edf get link to this team \u0111\u1ec3 th\u1ea5y TeamID trong link)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Install the Microsoft Teams PowerShell module if not already installed\nInstall-Module -Name MicrosoftTeams -Force -AllowClobber\n\n# Connect to Microsoft Teams\nConnect-MicrosoftTeams\n\n# Prompt for the Teams link\n$teamsLink = Read-Host \"Enter the Microsoft Teams link\"\n\n# Extract the Group ID from the link\nif ($teamsLink -match \"groupId=(&#91;a-f0-9-]+)\") {\n    $groupId = $matches&#91;1]\n} else {\n    Write-Host \"Invalid link. Please ensure it contains a Group ID.\" -ForegroundColor Red\n    exit\n}\n\n# Import the CSV file containing student emails\n$students = Import-Csv -Path \"students.csv\"\n\n# Add each student to the team\nforeach ($student in $students) {\n    Add-TeamUser -GroupId $groupId -User $student.Email\n}\n<\/code><\/pre>\n\n\n\n<p>Trong Powershell ch\u1ea1y l\u1ec7nh: .\\teams.ps1<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">H\u01b0\u1edbng d\u1eabn cho Mac OS<\/h2>\n\n\n\n<p>C\u00e0i Homebrew v\u00e0 Powershell cho Mac OS tr\u01b0\u1edbc:<\/p>\n\n\n\n<p><strong>Install Homebrew<\/strong>&nbsp;<\/p>\n\n\n\n<p><code>\/bin\/bash -c \"$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)\"<\/code><\/p>\n\n\n\n<p><strong>Install PowerShell<\/strong>:<\/p>\n\n\n\n<p><code>brew install --cask powershell<\/code><\/p>\n\n\n\n<p>T\u1ea1o file teams.ps1 v\u1edbi n\u1ed9i dung:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Function to extract Team ID from the Team link\nfunction Get-TeamIdFromLink {\n    param (\n        &#91;string]$TeamLink\n    )\n    # Extract the Team ID from the URL\n    if ($TeamLink -match \"groupId=(&#91;a-f0-9\\-]+)\") {\n        return $matches&#91;1]\n    } else {\n        throw \"Invalid Microsoft Teams link. Please ensure it includes the 'groupId' parameter.\"\n    }\n}\n\n# Prompt the user for the Microsoft Teams link\n$TeamLink = Read-Host \"Please enter the Microsoft Teams link\"\n\n# Extract the Team ID\ntry {\n    $TeamId = Get-TeamIdFromLink -TeamLink $TeamLink\n    Write-Output \"Extracted Team ID: $TeamId\"\n} catch {\n    Write-Error $_.Exception.Message\n    exit 1\n}\n\n# Prompt the user for the path to the CSV file\n$csvPath = Read-Host \"Please enter the full path to your CSV file\"\n\n# Check if the CSV file exists\nif (-not (Test-Path -Path $csvPath)) {\n    Write-Error \"The CSV file does not exist at the specified path.\"\n    exit 1\n}\n\n# Install the MicrosoftTeams module if not already installed\nif (-not (Get-Module -ListAvailable -Name MicrosoftTeams)) {\n    Install-Module -Name MicrosoftTeams -Force -AllowClobber\n}\n\n# Import the MicrosoftTeams module\nImport-Module MicrosoftTeams\n\n# Connect to Microsoft Teams\nConnect-MicrosoftTeams\n\n# Import members from the CSV file\n$Members = Import-Csv -Path $csvPath\n\n# Initialize an array to store successfully added members\n$SuccessList = @()\n\n# Add each member to the Microsoft Team\nforeach ($member in $Members) {\n    Write-Output \"Attempting to add $($member.Email) to the team...\"\n    try {\n        Add-TeamUser -GroupId $TeamId -User $member.Email -Role Member -Verbose\n        Write-Output \"Successfully added $($member.Email) to the team.\"\n        $SuccessList += $member.Email\n    } catch {\n        Write-Error \"Failed to add $($member.Email) to the team. Error: $_\"\n    }\n}\n\n# Disconnect from Microsoft Teams\nDisconnect-MicrosoftTeams\n\n# Report the successfully added members\nif ($SuccessList.Count -gt 0) {\n    Write-Output \"The following members were successfully added to the team:\"\n    $SuccessList | ForEach-Object { Write-Output $_ }\n} else {\n    Write-Output \"No members were successfully added.\"\n}<\/code><\/pre>\n\n\n\n<p>Ch\u1ea1y file teams.ps1 v\u1edbi command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pwsh teams.ps1\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Y\u00eau c\u1ea7u: File students.csv v\u1edbi header: Email (1 c\u1ed9t duy nh\u1ea5t) M\u1edf powershell as administrator Ch\u1ea1y l\u1ec7nh sau \u0111\u1ec3 m\u1edf Policy Execution: Set-ExecutionPolicy -Scope Process -ExecutionPolicy BypassT\u1ea1o file students.csv v\u1edbi 1 c\u1ed9t, header: Email t\u1ea1o file teams.ps1 v\u1edbi n\u1ed9i dung nh\u01b0 sau (c\u1ea7n thay teamId cho ph\u00f9 h\u1ee3p, m\u1edf get link to this team \u0111\u1ec3 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[50,151,23,150],"tags":[156,155,157,153,154,152],"class_list":["post-471","post","type-post","status-publish","format-standard","hentry","category-command","category-teams","category-tips-and-trick","category-windows","tag-add-member","tag-add-members","tag-add-multiple-members","tag-microsoft-teams","tag-powershell","tag-teams"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts\/471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=471"}],"version-history":[{"count":5,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts\/471\/revisions"}],"predecessor-version":[{"id":547,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=\/wp\/v2\/posts\/471\/revisions\/547"}],"wp:attachment":[{"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nbvps.anhtuanlqd.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}