Administration af Exchange Online Distributionsgrupper med PowerShell

I denne video gennemgår jeg hvordan vi kan fjerne en bruger fra flere Exchange Online distributionsgrupper ved hjælp af PowerShell.

Scriptet

$Login = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Login -Authentication Basic -AllowRedirection
Import-PSSession $Session

 $Bruger="peter.petersen@regionvest.onmicrosoft.com"

 $Distributionsgrupper= Get-DistributionGroup | where { (Get-DistributionGroupMember $_.Name | foreach {$_.PrimarySmtpAddress}) -contains "$Bruger"} 

 foreach( $dg in $Distributionsgrupper)
 {
 Write-Host "Fjerner $Bruger fra "$dg.name
 Remove-DistributionGroupMember $dg.name -Member $Bruger -Confirm:$False
 
 }
Advertisements

Skriv et svar