Wednesday 8 February 2023

PowerShell to block sign in to shared mailboxes on Microsoft 365

First you will need to connect to the following 365 services and bypass the security in powershell for the process

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Connect-ExchangeOnline
Connect-MsolService

Then run this

Get-EXOMailbox -Filter {recipienttypedetails -eq "SharedMailbox"} | get-MsolUser | Select-Object UserPrincipalName,blockcredential | Where {$_.BlockCredential -eq $False} | ForEach-Object { Set-MsolUser -UserPrincipalName $_.UserPrincipalName -BlockCredential $true}

No comments:

Post a Comment