Scaricare un elenco di utenti in portale di Azure

Microsoft Entra ID, parte di Microsoft Entra, supporta operazioni di download dell'elenco utenti in blocco.

Autorizzazioni necessarie

Sia gli utenti amministratori che gli utenti non amministratori possono scaricare gli elenchi di utenti.

Per scaricare un elenco di utenti

Suggerimento

I passaggi descritti in questo articolo possono variare leggermente in base al portale da cui si inizia.

  1. Accedi all'Interfaccia di amministrazione di Microsoft Entra.

  2. Selezionare Microsoft Entra ID.

  3. Selezionare Utenti>Tutti gli utenti Scarica utenti.> Per impostazione predefinita, tutti i profili utente vengono esportati.

  4. Nella pagina Scarica gli utenti seleziona Avvia per ricevere un file CSV che elenca le proprietà del profilo utente. Se sono presenti errori, è possibile scaricare e visualizzare il file dei risultati nella pagina Risultati dell'operazione in blocco. Il file contiene il motivo di ogni errore.

    Screenshot della selezione della posizione in cui si vuole visualizzare l'elenco degli utenti da scaricare.

Nota

Il file di download conterrà l'elenco filtrato degli utenti in base all'ambito dei filtri applicati.

Sono inclusi gli attributi utente seguenti:

  • userPrincipalName
  • displayName
  • surname
  • mail
  • givenName
  • objectId
  • userType
  • jobTitle
  • department
  • accountEnabled
  • usageLocation
  • streetAddress
  • state
  • country
  • physicalDeliveryOfficeName
  • city
  • postalCode
  • telephoneNumber
  • mobile
  • authenticationAlternativePhoneNumber
  • authenticationEmail
  • alternateEmailAddress
  • ageGroup
  • consentProvidedForMinor
  • legalAgeGroupClassification

Verificare lo stato

È possibile visualizzare lo stato delle richieste bulk in sospeso nella pagina Risultati dell'operazione bulk.

Screenshot del controllo dello stato nella pagina Risultati operazioni bulk.

Se si verificano errori, è possibile scaricare e visualizzare il file dei risultati nella pagina Risultati dell'operazione bulk. Il file contiene il motivo di ogni errore. L'invio del file deve corrispondere al modello usato e includere i nomi esatti della colonna. Per altre informazioni sulle limitazioni delle operazioni bulk, vedere Limiti del servizio di download bulk.

Limiti del servizio di download in blocco

È necessario tenere presente che ogni attività di operazioni bulk può essere eseguita per un massimo di un'ora.

Le operazioni in blocco nel portale di amministrazione di Microsoft Entra potrebbero verificarsi un timeout e un errore in tenant molto grandi. Questa limitazione è un problema noto dovuto alle limitazioni di ridimensionamento. Il team di progettazione Microsoft sta lavorando a un nuovo servizio che risolverà questa limitazione.The Microsoft engineering team is working on a new service that will endly address this limitation.

Nota

Quando si eseguono operazioni bulk, ad esempio l'importazione o la creazione, è possibile che si verifichi un problema se l'operazione bulk non viene completata entro l'ora. Per risolvere questo problema, è consigliabile suddividere il numero di record elaborati per batch. Ad esempio, prima di avviare un'esportazione, è possibile limitare il set di risultati filtrando in base a un tipo di gruppo o a un nome utente per ridurre le dimensioni dei risultati. Affinando i filtri, essenzialmente si limitano i dati restituiti dall'operazione in blocco.

Un'altra soluzione alternativa per questo problema consiste nell'usare PowerShell per effettuare chiamate dirette all'API Microsoft Graph. Per gli errori di download in blocco di utenti e gruppi, è consigliabile usare i GET-MgGroup -All cmdlet di PowerShell e GET-MgUser -All.

Gli esempi di codice di PowerShell seguenti sono relativi alle operazioni bulk correlate a:

Utenti

Scaricare in blocco tutti gli utenti

# 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" 

Creare utenti in blocco

# 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." 

Nota

Assicurarsi che il file CSV contenga le colonne necessarie, ad esempio DisplayName, UserPrincipalNamee così via. Modificare anche lo script in modo che corrisponda ai nomi di colonna effettivi nel file CSV.

Eliminare utenti in blocco

# 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." 

Nota

Assicurarsi che il file CSV contenga le colonne necessarie, ad esempio UserPrincipalName. Modificare anche lo script in modo che corrisponda ai nomi di colonna effettivi nel file CSV.

Gruppi

Scaricare in blocco tutti i gruppi

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\\cewu\\Documents\\Groups.csv" 

 $groupData| Export-Csv -Path $outputCsvPath -NoTypeInformation 
 
 Write-Host "Group members exported to $outputCsvPath" 

Scaricare in blocco i membri di un gruppo

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"  

Aggiungere membri in blocco

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 

Rimuovere membri in blocco

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 

Dispositivi

Scaricare in blocco tutti i dispositivi

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"  

Passaggi successivi