จะลบผู้ใช้ออกจากกลุ่ม Office 365 โดยใช้ PowerShell ได้อย่างไร
ความต้องการ: ลบผู้ใช้ออกจากกลุ่ม Office 365 โดยใช้ PowerShell
จะลบผู้ใช้ออกจากกลุ่ม Office 365 ได้อย่างไร
กลุ่ม Microsoft 365 เป็นเครื่องมือสำคัญสำหรับการทำงานร่วมกันและการสื่อสารภายในองค์กร หากคุณเป็นผู้ดูแลระบบ Office 365 อาจมีบางครั้งที่คุณต้องลบผู้ใช้ออกจากกลุ่ม บทความนี้จะแสดงวิธีลบผู้ใช้ออกจากกลุ่ม Office 365 โดยใช้ PowerShell และ Azure Active Directory Module สำหรับ PowerShell นอกจากนี้เรายังจะแสดงวิธีลบผู้ใช้ออกจากกลุ่ม Office 365 โดยใช้ศูนย์การจัดการ Microsoft 365
ลบผู้ใช้ออกจากกลุ่ม Microsoft 365 โดยใช้ศูนย์การจัดการ Microsoft 365
คุณสามารถลบสมาชิกออกจากกลุ่ม Office 365 ผ่านทางศูนย์การจัดการ Microsoft 365 ในฐานะผู้ดูแลระบบ นี่คือวิธีการ:
- เข้าสู่ระบบไซต์ศูนย์การจัดการ Microsoft 365: https://admin.microsoft.com
- ขยาย "ทีมและกลุ่ม" และคลิกที่ "ทีมและกลุ่มที่ใช้งานอยู่" ในการนำทางด้านซ้าย
- ค้นหาและเลือกกลุ่ม Office 365 ที่คุณต้องการลบสมาชิก
- ในหน้ารายละเอียดกลุ่ม คลิกแท็บ "สมาชิก" >>เลือกผู้ใช้ที่คุณต้องการลบ
ตอนนี้คุณสามารถลบสมาชิกกลุ่มได้โดยคลิกที่ปุ่ม “ลบเป็นสมาชิก” ถัดจากสมาชิกแต่ละคน คุณยังสามารถเลือกผู้ใช้หลายคนและลบออกได้ในคลิกเดียว ในทำนองเดียวกัน คุณสามารถคลิกที่แท็บ "เจ้าของ" เพื่อลบเจ้าของกลุ่มได้
- กดปิดเมื่อคุณทำเสร็จแล้ว!
จะลบการเป็นสมาชิกกลุ่มของผู้ใช้ Microsoft 365 ได้อย่างไร
แทนที่จะไปที่กลุ่ม คุณสามารถดำเนินการผ่านผู้ใช้ที่ระบุและลบการเป็นสมาชิกกลุ่มได้ นี่คือวิธีการ:
- เปิดแอปผู้ดูแลระบบใน Office 365 >> ในบานหน้าต่างนำทางด้านซ้าย เลือกผู้ใช้ >> ผู้ใช้ที่ใช้งานอยู่
- ค้นหาผู้ใช้ที่คุณต้องการลบ เลือกจุดสามจุดจากออบเจ็กต์ผู้ใช้ จากนั้นเลือก "จัดการกลุ่ม"
ในหน้าต่างถัดไป เลือกกลุ่มที่คุณต้องการลบ และคลิกที่ปุ่ม "ลบ" และยืนยันข้อความแจ้ง
PowerShell เพื่อลบผู้ใช้ออกจากกลุ่ม Office 365
วิธีที่ง่ายและรวดเร็วในการลบผู้ใช้ออกจากกลุ่ม Office 365 คือการใช้ Azure AD PowerShell นี่คือวิธีที่เราสามารถใช้ PowerShell เพื่อลบผู้ใช้ออกจากกลุ่ม Office 365:
#Variables
$GroupName = "IT Team"
$UserUPN = "salaudeen@crescent.com"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential)
#Get the Azure AD Group
$AADGroup = Get-AzureADGroup -Filter "DisplayName eq '$GroupName'"
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"
#Remove User from Group
Remove-AzureADGroupMember -ObjectId $AADGroup.ObjectID -MemberId $AADUser.ObjectID
ในทำนองเดียวกัน คุณสามารถลบผู้ใช้ออกจากกลุ่ม Office 365 ทั้งหมดได้อย่างรวดเร็วผ่าน PowerShell เป็น:
#Variables
$UserUPN = "salaudeen@crescent.com"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null
#Get all Azure AD Unified Groups
$AADGroups = Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"
#Check each group for the user
ForEach ($Group in $AADGroups)
{
$GroupMembers = (Get-AzureADGroupMember -ObjectId $Group.id).UserPrincipalName
If ($GroupMembers -contains $UserUPN)
{
#Remove user from Group
Remove-AzureADGroupMember -ObjectId $Group.Id -MemberId $AADUser.ObjectId
Write-Output "$UserUPN was removed from $($Group.DisplayName)"
}
}
วิธีการลบผู้ใช้หลายรายในกลุ่ม Microsoft 365 ออกจากไฟล์ CSV ไฟล์ CSV ของฉันมีคอลัมน์ “UPN” พร้อมรหัสเข้าสู่ระบบของผู้ใช้
#Variables
$CSVFile = "C:\Temp\UserList.csv"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null
#Get all Azure AD Unified Groups
$AADGroups = Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true
#Iterate through each line in CSV
Import-CSV $CSVFile | ForEach-Object {
#Get the UPN
$UPN = $_.UPN
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UPN'"
#Check each group for the user
ForEach ($Group in $AADGroups)
{
$GroupMembers = (Get-AzureADGroupMember -ObjectId $Group.id).UserPrincipalName
If ($GroupMembers -contains $UPN)
{
#Remove user from Group
Remove-AzureADGroupMember -ObjectId $Group.Id -MemberId $AADUser.ObjectId
Write-Output "$UPN is removed from Group '$($Group.DisplayName)'"
}
}
}
ลบสมาชิกกลุ่ม Office 365 ด้วย Exchange Online PowerShell
เราสามารถลบสมาชิกกลุ่ม Microsoft 365 ด้วย Exchange Online PowerShell ได้เช่นกัน:
#Connect to Exchange Online
Connect-ExchangeOnline -Credential (Get-Credential) -ShowBanner:$false
#PowerShell to remove a Member from office 365 group
Remove-UnifiedGrouplinks -Identity "Procurement@Crescent.com" -LinkType "Members" -Links "Steve@Crescent.com"
PnP PowerShell เพื่อลบสมาชิกออกจากกลุ่ม Office 365
ใช้ Remove-PnPMicrosoft365GroupMember cmdlet เพื่อลบสมาชิกออกจากกลุ่ม Microsoft 365
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$GroupEmail = "HRAdmin@Crescent.com"
$MemberToRemove = "Alex@Crescent.com"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get the Office 365 Group from Email
$Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail
#Check if group exists
If($Group -ne $Null)
{
#Get Group Members
$GroupMembers = Get-PnPMicrosoft365GroupMembers -Identity $Group | Select -ExpandProperty Email
If($GroupMembers -contains $MemberToRemove)
{
#Remove Member from Office 365 group
Remove-PnPMicrosoft365GroupMember -Identity $Group -Users $MemberToRemove
Write-Host "Member removed from the Group Successfully!" -f Green
}
Else
{
Write-Host "Could not find Member in the Group!" -f Yellow
}
}
Else
{
Write-host "Could not Find Group!" -f Yellow
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
หากคุณต้องการลบสมาชิกทั้งหมดออกจากกลุ่ม Microsoft 365 ให้ใช้ cmdlet: Clear-PnPMicrosoft365GroupMember
ในทำนองเดียวกัน คุณสามารถลบเจ้าของกลุ่มได้โดยใช้ Remove-PnPMicrosoft365GroupOwner cmdlet:
#Config Variables
$AdminSiteURL = "https://salaudeen-admin.sharepoint.com"
$GroupEmail = "HRAdmin@lsqp.onmicrosoft.com"
$OwnersToRemove = "Alexw@lsqp.onmicrosoft.com"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get the Office 365 Group from Email
$Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail
#Check if group exists
If($Group -ne $Null)
{
#Get Group Owners
$GroupOwners = Get-PnPMicrosoft365GroupOwner -Identity $Group | Select -ExpandProperty Email
If($GroupOwners -contains $OwnersToRemove)
{
#Remove Owner from Office 365 group
Remove-PnPMicrosoft365GroupOwner -Identity $Group -Users $OwnersToRemove
Write-Host "Owner removed from the Group Successfully!" -f Green
}
Else
{
Write-Host "Could not find Owner in the Group!" -f Yellow
}
}
Else
{
Write-host "Could not Find Group!" -f Yellow
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
PnP PowerShell เพื่อลบผู้ใช้ออกจากกลุ่มที่เกี่ยวข้องของไซต์ SharePoint Online
เมื่อไซต์เชื่อมต่อกับกลุ่ม Microsoft 365 สิทธิ์สามารถจัดการได้ในระดับกลุ่ม เช่น หากต้องการลบผู้ใช้ออกจากไซต์ คุณต้องลบเขาออกจากกลุ่ม
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/CorporateBranding"
$UserId= "Steve@crescent.onmicrosoft.com"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the Site
$Site = Get-PnPSite -Includes GroupId
#Remove user from the Site's associated Microsoft 365 Group
Remove-PnPMicrosoft365GroupMember -Identity $Site.GroupId -Users $UserId
Write-host "Removed User from the Associated Microsoft 365 Group!" -f Green
}
Catch {
Write-host -f Red "Error:" $_.Exception.Message
}
ในทำนองเดียวกัน หากต้องการลบผู้ใช้ออกจากเจ้าของกลุ่ม ให้ใช้สิ่งต่อไปนี้:
Remove-PnPMicrosoft365GroupOwner -Identity $Site.GroupId -Users $UserId
ห่อ
โดยสรุป การลบผู้ใช้ออกจากกลุ่ม Microsoft 365 เป็นกระบวนการที่ไม่ซับซ้อนซึ่งสามารถทำได้โดยใช้ศูนย์การจัดการ Microsoft 365 หรือใช้ PowerShell การลบผู้ใช้ที่ไม่ได้เป็นส่วนหนึ่งขององค์กรอีกต่อไปหรือไม่จำเป็นต้องเข้าถึงทรัพยากรของกลุ่มอีกต่อไป ผู้ดูแลระบบสามารถมั่นใจในความปลอดภัยและความเป็นส่วนตัวของข้อมูลที่อยู่ในกลุ่มได้

