Massåtgärder
Med massåtgärder i Microsoft Entra-ID kan du utföra åtgärder på flera entiteter, till exempel användare, grupper och enheter, samtidigt. Det kan vara att skapa, ta bort eller uppdatera flera poster i en enda åtgärd, vilket kan effektivisera administrativa uppgifter avsevärt och förbättra effektiviteten.
Massåtgärder i Microsoft Entra-administratörsportalen kan överskrida tidsgränsen och misslyckas för mycket stora klienter. Den här begränsningen är ett känt problem på grund av skalningsbegränsningar. Microsofts teknikteam arbetar med en ny tjänst som så småningom kommer att åtgärda den här begränsningen.
Kommentar
När du utför massåtgärder, till exempel importera eller skapa, kan det uppstå ett problem om massåtgärden inte slutförs inom en timme. För att undvika det här problemet rekommenderar vi att du delar upp antalet poster som bearbetas per batch. Innan du till exempel startar en export kan du begränsa resultatuppsättningen genom att filtrera efter en grupptyp eller ett användarnamn för att minska resultatets storlek. Genom att förfina dina filter begränsar du i princip de data som returneras av massåtgärden.
Lösning för massåtgärder
En lösning på det här problemet är att använda PowerShell för att göra direkta Microsoft Graph API-anrop. Vid massnedladdning av användare och grupper rekommenderar vi att du använder PowerShell-cmdletarna GET-MgGroup -All
och GET-MgUser -All
.
Följande PowerShell-kodexempel är för massåtgärder relaterade till:
Användare
Massnedladdning av alla användare
# 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"
Masskapa användare
# 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."
Kommentar
Kontrollera att CSV-filen innehåller de kolumner som behövs (till exempel DisplayName
, , UserPrincipalName
och så vidare). Justera även skriptet så att det matchar de faktiska kolumnnamnen i CSV-filen.
Massborttag användare
# 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."
Kommentar
Kontrollera att CSV-filen innehåller de kolumner som behövs (till exempel UserPrincipalName
). Justera även skriptet så att det matchar de faktiska kolumnnamnen i CSV-filen.
Grupper
Massnedladdning av alla grupper
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
MemebershipType = $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"
Massnedladdning av medlemmar i en grupp
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"
Lägga till medlemmar i grupp
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
Ta bort medlemmar i grupp
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
Enheter
Massnedladdning av alla enheter
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"