Zum Inhalt
Kaffeeundcode
Skriptbibliothek
PowerShell 06.10.2026

PowerShell

Set GroupOwner

115_Set-GroupOwner.ps1

<#
.SYNOPSIS
    Fügt einen Owner zu einer Gruppe hinzu.

.DESCRIPTION
    <!-- library-status:start -->
    Prüfstatus: Ungeprüft
    Windows- und Tenant-Abnahme ausstehend; keine pauschale Produktionsfreigabe.

    <!-- library-status:end -->

    Macht einen User zum Besitzer einer Gruppe.
    Erfordert die Berechtigung 'Group.ReadWrite.All'.

.NOTES
    File Name: 115_Set-GroupOwner.ps1
    Author: Mattia Cirillo
    Version: 1.0
#>

param (
    [string]$GroupName,
    [string]$OwnerUPN
)

Connect-MgGraph -Scopes "Group.ReadWrite.All"

$Group = Get-MgGroup -Filter "displayName eq '$GroupName'"
$User = Get-MgUser -UserId $OwnerUPN

if ($Group -and $User) {
    New-MgGroupOwnerByRef -GroupId $Group.Id -DirectoryObjectId $User.Id
    Write-Host "Owner hinzugefügt."
}