Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Questo articolo illustra come gestire i gruppi in Microsoft Entra ID usando Microsoft Entra PowerShell. Gli esempi includono la creazione e l'aggiornamento di gruppi, l'aggiunta di utenti e proprietari, l'esecuzione di query senza proprietario e gruppi vuoti.
Prerequisiti
- Un account utente di Microsoft Entra. Se non si dispone già di un account, è possibile creare un account gratuitamente.
- Installare la versione più recente Microsoft Entra modulo di PowerShell. Per altre informazioni, vedere Installare il modulo di PowerShell Microsoft Entra.
- Avere almeno il ruolo Amministratore gruppi.
Crea gruppi
Per creare un gruppo, assicurarsi di disporre delle autorizzazioni necessarie per creare un gruppo.
Connect-Entra -Scopes 'Group.ReadWrite.All'
Per creare un nuovo gruppo, eseguire il comando seguente.
$groupParams = @{
DisplayName = 'Contoso marketing'
MailEnabled = $false
SecurityEnabled = $true
MailNickName = 'NotSet'
}
New-EntraGroup @groupParams
DisplayName Id MailNickname Description GroupTypes
----------- -- ------------ ----------- ----------
Contoso marketing aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb NotSet {}
Questo comando crea un nuovo gruppo con il nome Contoso marketing.
Cercare il gruppo creato usando il comando seguente.
Get-EntraGroup -Filter "displayName eq 'Contoso marketing'"
DisplayName Id MailNickname Description GroupTypes
----------- -- ------------ ----------- ----------
Contoso marketing aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb NotSet Contoso marketing EMEA {}
Questo comando restituisce i dettagli del gruppo appena creato. È anche possibile usare il GroupId (GUID) per cercare, aggiornare o eliminare il gruppo.
Aggiornare i dettagli del gruppo
Aggiornare la descrizione del gruppo eseguendo il comando seguente.
Get-EntraGroup -Filter "displayName eq 'Contoso marketing'" | Set-EntraGroup -Description 'Contoso marketing Global'
Per confermare la descrizione aggiornata, eseguire nuovamente Get-EntraGroup .
Get-EntraGroup -Filter "displayName eq 'Contoso marketing'"
Aggiungere un utente a un gruppo
Aggiungere un utente al gruppo eseguendo il comando seguente.
GroupId è l'ID gruppo e MemberId è l'ID utente. È possibile ottenere l'ID utente dal Interfaccia di amministrazione di Microsoft Entra o eseguendo il comando Get-EntraUser.
$group = Get-EntraGroup -Filter "displayName eq 'Contoso marketing'"
$user = Get-EntraUser -UserId 'SawyerM@contoso.com'
Add-EntraGroupMember -GroupId $group.Id -MemberId $user.Id
Per recuperare i membri del gruppo, usare il comando :
$group = Get-EntraGroup -Filter "displayName eq 'Contoso marketing'"
Get-EntraGroup -GroupId $group.Id | Get-EntraGroupMember | Select-Object Id, DisplayName, '@odata.type'
Id DisplayName @odata.type
------------------------------------ ----------------- -------------------------------
dddddddd-3333-4444-5555-eeeeeeeeeeee Sawyer Miller #microsoft.graph.user
eeeeeeee-4444-5555-6666-ffffffffffff Alex Wilber #microsoft.graph.user
aaaaaaaa-6666-7777-8888-bbbbbbbbbbbb My Application #microsoft.graph.servicePrincipal
cccccccc-8888-9999-0000-dddddddddddd Contoso Group #microsoft.graph.group
Aggiungere un utente come proprietario del gruppo
Aggiungere un proprietario del gruppo a un gruppo eseguendo il comando seguente.
GroupId è l'ID gruppo e OwnerId è l'ID utente.
$group = Get-EntraGroup -Filter "displayName eq 'Contoso marketing'"
$owner = Get-EntraUser -UserId 'AdeleV@contoso.com'
Add-EntraGroupOwner -GroupId $group.Id -OwnerId $owner.Id
Per confermare il proprietario del gruppo aggiornato, usare il comando :
$group = Get-EntraGroup -Filter "displayName eq 'Contoso marketing'"
Get-EntraGroup -GroupId $group.Id | Get-EntraGroupOwner | Select-Object Id, DisplayName, '@odata.type'
Id DisplayName @odata.type
------------------------------------ ----------------- ---------------------------
aaaaaaaa-6666-7777-8888-bbbbbbbbbbbb Adele Vance #microsoft.graph.user
Interrogare gruppi senza proprietario o vuoti
Per eseguire query sui gruppi senza proprietari, eseguire il comando seguente.
$allGroups = Get-EntraGroup -All
$groupsWithoutOwners = foreach ($group in $allGroups) {
$owners = Get-EntraGroupOwner -GroupId $group.Id
if ($owners.Count -eq 0) {
$group
}
}
$groupsWithoutOwners | Format-Table DisplayName, Id, GroupTypes
DisplayName Id GroupTypes
----------- -- ----------
Contoso marketing aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb {}
HelpDesk admin group eeeeeeee-4444-5555-6666-ffffffffffff {}
Per eseguire query sui gruppi senza membri (gruppi vuoti), eseguire il comando seguente.
$allGroups = Get-EntraGroup -All
$groupsWithoutMembers = foreach ($group in $allGroups) {
$members = Get-EntraGroupMember -GroupId $group.Id
if ($members.Count -eq 0) {
$group
}
}
$groupsWithoutMembers | Format-Table DisplayName, Id, GroupTypes
DisplayName Id GroupTypes
----------- -- ----------
Contoso marketing aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb {}
HelpDesk admin group eeeeeeee-4444-5555-6666-ffffffffffff {}
Pulire le risorse
Per rimuovere il gruppo, usare il comando :
Get-EntraGroup -Filter "displayName eq 'Contoso marketing'" | Remove-EntraGroup