Operasi massal
Operasi massal di MICROSOFT Entra ID memungkinkan Anda melakukan tindakan pada beberapa entitas, seperti pengguna, grup, dan perangkat, sekaligus. Tindakan ini dapat mencakup membuat, menghapus, atau memperbarui beberapa rekaman dalam satu operasi. Operasi massal dapat sangat menyederhanakan tugas administratif dan meningkatkan efisiensi.
Operasi massal di portal admin Microsoft Entra dapat kehabisan waktu dan gagal pada penyewa besar. Batasan ini adalah masalah yang diketahui karena keterbatasan penskalaan.
Catatan
Saat melakukan operasi massal, seperti mengimpor atau membuat, Anda mungkin mengalami masalah jika operasi massal tidak selesai dalam satu jam. Untuk mengatasi masalah ini, sebaiknya pisahkan jumlah rekaman yang diproses per batch. Misalnya, sebelum memulai ekspor, Anda dapat membatasi hasil yang ditetapkan dengan memfilter jenis grup atau nama pengguna untuk mengurangi ukuran hasil. Dengan menyempurnakan filter Anda, sebenarnya Anda membatasi data yang dihasilkan oleh operasi massal.
Solusi sementara untuk operasi massal
Solusi untuk masalah ini adalah menggunakan PowerShell untuk melakukan panggilan LANGSUNG Microsoft Graph API. Untuk kegagalan pengguna dan grup saat mengunduh secara massal, sebaiknya gunakan cmdlet PowerShell GET-MgGroup -All
dan GET-MgUser -All
.
Contoh kode PowerShell berikut adalah untuk operasi massal yang terkait dengan:
Pengguna
Unduh data semua pengguna
# Import the Microsoft Graph module
Import-Module Microsoft.Graph
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "User.Read.All"
# Get all users using Get-MgUser
$users = Get-MgUser -All -ConsistencyLevel eventual -Property Id, DisplayName, UserPrincipalName,UserType,OnPremisesSyncEnabled,CompanyName,CreationType
# Specify the output CSV file path
$outputCsvPath = "C:\\Users\\YourUsername\\Documents\\Users.csv"
# Create a custom object to store user data
$userData = @()
# Loop through each user and collect relevant data
foreach ($user in $users) {
$userObject = [PSCustomObject]@{
Id = $user.Id
DisplayName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
UserType = $user.UserType
OnPremisesSyncEnabled = $user.OnPremisesSyncEnabled
CompanyName = $user.CompanyName
CreationType = $user.CreationType
}
$userData += $userObject
}
# Export user data to a CSV file
$userData | Export-Csv -Path $outputCsvPath -NoTypeInformation
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Write-Host "User data exported to $outputCsvPath"
Membuat pengguna
# Import the Microsoft Graph module
Import-Module Microsoft.Graph
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Specify the path to the CSV file containing user data
$csvFilePath = "C:\\Path\\To\\Your\\Users.csv"
# Read the CSV file (adjust the column names as needed)
$usersData = Import-Csv -Path $csvFilePath
# Loop through each row in the CSV and create users \
foreach ($userRow in $usersData) {
$userParams = @{
DisplayName = $userRow.'Name [displayName] Required'
UserPrincipalName = $userRow.'User name [userPrincipalName] Required'
PasswordProfile = @{
Password = $userRow.'Initial password [passwordProfile] Required'
}
AccountEnabled = $true
MailNickName = $userRow.mailNickName
}
try {
New-MgUser @userParams
Write-Host "User $($userRow.UserPrincipalName) created successfully."
} catch {
Write-Host "Error creating user $($userRow.UserPrincipalName): $($_.Exception.Message)"
}
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Write-Host "Bulk user creation completed."
Catatan
Pastikan file CSV Anda berisi kolom yang diperlukan (misalnya; DisplayName
, , UserPrincipalName
dan sebagainya). Selain itu, sesuaikan skrip agar sesuai dengan nama kolom aktual dalam file CSV Anda.
Menghapus pengguna
# Import the Microsoft Graph module
Import-Module Microsoft.Graph
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Specify the path to the CSV file containing user data
$csvFilePath = "C:\\Path\\To\\Your\\Users.csv"
# Read the CSV file (adjust the column names as needed)
$usersData = Import-Csv -Path $csvFilePath
# Loop through each row in the CSV and delete users
foreach ($userRow in $usersData) {
try {
Remove-MgUser -UserId $userRow.UserPrincipalName -Confirm:$false
Write-Host "User $($userRow.UserPrincipalName) deleted successfully."
} catch {
Write-Host "Error deleting user $($userRow.UserPrincipalName): $($_.Exception.Message)"
}
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Write-Host "Bulk user deletion completed."
Catatan
Pastikan file CSV Anda berisi kolom yang diperlukan (misalnya, UserPrincipalName
). Selain itu, sesuaikan skrip agar sesuai dengan nama kolom aktual dalam file CSV Anda.
Grup
Mengunduh semua grup sekaligus
Import-Module Microsoft.Graph.Groups
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "Group.Read.All"
# Get the group members
$groups = Get-MgGroup -All | Select displayName, Id, groupTypes,mail
# Create a custom object to store group data
$groupData = @()
# Loop through each group and collect relevant data
foreach ($group in $groups) {
if ($group.groupTypes -contains "Unified"){$groupType = "Microsoft 365"}
else {$groupType = "Security"}
if ($group.groupTypes -contains "DynamicMembership"){$membershipType = "Dynamic"}
else {$membershipType = "Assigned"}
$groupObject = [PSCustomObject]@{
Id = $group.Id
DisplayName = $group.displayName
Mail = $group.mail
GroupType = $groupType
MembershipType = $membershipType
}
$groupData += $groupObject
}
# Specify the output CSV file path
$outputCsvPath = "C:\\Users\\<YourUsername>\\Documents\\Groups.csv"
$groupData| Export-Csv -Path $outputCsvPath -NoTypeInformation
Write-Host "Group members exported to $outputCsvPath"
Mengunduh anggota grup dalam jumlah banyak
Import-Module Microsoft.Graph.Groups
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "Group.Read.All,GroupMember.Read.All"
# Set the group ID of the group whose members you want to download
$groupId = "your_group_id"
# Get the group members
$members = Get-MgGroupMember -GroupId $groupId -All | select * -ExpandProperty additionalProperties | Select-Object @(
'id'
@{ Name = 'userPrincipalName'
Expression = { $_.AdditionalProperties["userPrincipalName"] }
}
@{ Name = 'displayName'
Expression = { $_.AdditionalProperties["displayName"] }
}
)
# Specify the output CSV file path
$outputCsvPath = "C:\\Users\\YourUserName\\Documents\\GroupMembers.csv"
$members| Export-Csv -Path $outputCsvPath -NoTypeInformation
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Write-Host "Group members exported to $outputCsvPath"
Menambahkan anggota secara massal
Import-Module Microsoft.Graph.Groups
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "GroupMember.ReadWrite.All"
# Import the CSV file
$members = Import-Csv -Path "C:\path\to\your\file.csv"
# Define the Group ID
$groupId = "your-group-id"
# Iterate over each member and add them to the group
foreach ($member in $members) {
try{
New-MgGroupMember -GroupId $groupId -DirectoryObjectId $member.memberObjectId
Write-Host "Added $($member.memberObjectId) to the group."
}
Catch{
Write-Host "Error adding member $($member.memberObjectId):$($_.Exception.Message)"
}
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Menghapus anggota secara massal
Import-Module Microsoft.Graph.Groups
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "GroupMember.ReadWrite.All"
# Import the CSV file
$members = Import-Csv -Path "C:\path\to\your\file.csv"
# Define the Group ID
$groupId = "your-group-id"
# Iterate over each member and add them to the group
foreach ($member in $members) {
try{
Remove-MgGroupMemberByRef -GroupId $groupId -DirectoryObjectId $member.memberObjectId \
Write-Host "Removed $($member.memberObjectId) from the group."
}
Catch{
Write-Host "Error removing member $($member.memberObjectId):$($_.Exception.Message)"
}
}
# Disconnect from Microsoft Graph
Disconnect-MgGraph
Perangkat
Mengunduh semua perangkat secara massal
Import-Module Microsoft.Graph
# Authenticate to Microsoft Graph (you may need to provide your credentials)
Connect-MgGraph -Scopes "Device.Read.All"
# Get all devices
$devices = Get-MgDevice -All |select displayName,deviceId,operatingSystem,operatingSystemVersion,isManaged,isCompliant,mdmAppId,registeredOwners,TrustType
# Specify the output CSV file path
$outputCsvPath = "C:\\Users\\YourUserName\\Documents\\Devices.csv"
$devices| Export-Csv -Path $outputCsvPath -NoTypeInformation
Write-Host "Devices exported to $outputCsvPath"