20. februar 2025

Tildel en bruger rettigheder til undermapper i delt postkasse

Connect først 



$Username = "postkasse@domain.dk" 

$AddUsername = "bruger@domain.dk" 

$CustomFolder = Get-MailboxFolderStatistics -Identity $Username -FolderScope All | Where-Object {$_.FolderPath -like '/Indbakke/Undermappe*'} 

foreach ($CustomSubFolder in $CustomFolder) { Add-MailboxFolderPermission -Identity "$($Username):$($CustomSubFolder.FolderPath.Replace("/","\"))" -User $AddUsername -AccessRights Owner }

Exchange Online Management PowerShell Connect-ExchangeOnline bug "A window handle must be configured

SOLVED: Exchange Online Management PowerShell Connect-ExchangeOnline bug "A window handle must be configured. See https://aka.ms/msal-net-wam#parent-window-handles" 

 

 

 

Workaround 3: Handle MSAL Authentication yourself 

The best solution is to handle the MSAL authentication yourself and then pass an access token to Connect-ExchangeOnline. The Exchange team are constantly shunning standards (the whole backend of these cmdlets are a botched REST API that passes the cmdlet name) so you're really stuck with the cmdlets but you can at least rid yourself of their authentication code. 

 

The following sample code uses the MSAL libraries that are installed as part of the Exchange PowerShell cmdlets so you don't need to install these separately. 

$msalPath = [System.IO.Path]::GetDirectoryName((Get-Module ExchangeOnlineManagement).Path); 
Add-Type -Path "$msalPath\Microsoft.IdentityModel.Abstractions.dll"; 
Add-Type -Path "$msalPath\Microsoft.Identity.Client.dll"; 
[Microsoft.Identity.Client.IPublicClientApplication] $application = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::Create("fb78d390-0c51-40cd-8e17-fdbfab77341b").WithDefaultRedirectUri().Build(); 
$result = $application.AcquireTokenInteractive([string[]]"https://outlook.office365.com/.default").ExecuteAsync().Result; 
Connect-ExchangeOnline -AccessToken $result.AccessToken -UserPrincipalName $result.Account.Username