{"id":7,"date":"2025-01-03T06:44:17","date_gmt":"2025-01-03T06:44:17","guid":{"rendered":"https:\/\/huongdan.anhtuanlqd.com\/?p=6"},"modified":"2025-01-03T06:44:17","modified_gmt":"2025-01-03T06:44:17","slug":"add-multiple-teams-members","status":"publish","type":"post","link":"https:\/\/hd.follbc.org\/?p=7","title":{"rendered":"ADD MULTIPLE TEAMS MEMBERS"},"content":{"rendered":"\n<p> <a href=\"https:\/\/github.com\/tuanna-git\/teams_member\">https:\/\/github.com\/tuanna-git\/teams_member<\/a><\/p>\n\n\n\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). Save \u1edf Desktop cho ti\u1ec7n.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Windows:<\/h2>\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:&nbsp;<\/p>\n\n\n\n<p><strong>Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass<br><\/strong><\/p>\n\n\n\n<p>t\u1ea1o file<strong>&nbsp;teams.ps1&nbsp;<\/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<h2 class=\"wp-block-heading\">H\u01b0\u1edbng D\u1eabn Cho Mac OS<\/h2>\n\n\n\n<p>C\u1ea7n file &#8220;student.csv&#8221; nh\u01b0 tr\u00ean, save \u1edf \u0111\u00e2u th\u00ec t\u1eb9o nh\u1edb g\u00f5 \u0111\u01b0\u1eddng d\u1eabn cho \u0111\u00fang. V\u00ed d\u1ee5 \u0111\u1ec3 \u1edf \u1ed5 DATA. &#8220;\/Volumes\/DATA\/student.csv&#8221;<\/p>\n\n\n\n<p>File students.csv v\u1edbi header: Email (1 c\u1ed9t duy nh\u1ea5t)<\/p>\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: trong Terminal d\u00f9ng &#8220;nano&#8221; r\u1ed3i copy paste. N\u1ebfu d\u00f9ng Textedit t\u1ea1o file m\u1edbi th\u00ec Format =&gt; Make Plain Text, r\u1ed3i paste v\u00e0 save v\u1edbi \u0111\u00fang t\u00ean file teams.ps1 (nh\u1edb b\u1ecf d\u1ea5u tick t\u1ef1 \u0111\u1ed9ng th\u00eam .txt c\u1ee7a TextEdit)<\/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<\/code><\/pre>\n\n\n\n<p>N\u1ebfu add kh\u00f4ng fail email n\u00e0o th\u00ec s\u1ebd kh\u00f4ng th\u1ea5y b\u00e1o fail.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/github.com\/tuanna-git\/teams_member Y\u00eau c\u1ea7u: File students.csv v\u1edbi header: Email (1 c\u1ed9t duy nh\u1ea5t). Save \u1edf Desktop [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,7],"tags":[2,3,4,6],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-teams","category-windows","tag-add-members","tag-microsoft-teams","tag-powershell","tag-teams"],"_links":{"self":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hd.follbc.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}