Skip to content

Instantly share code, notes, and snippets.

@jamiechalmerzlp
Created August 15, 2022 07:59
Show Gist options
  • Select an option

  • Save jamiechalmerzlp/d0674f17c28393adfbc7c8fefc304e91 to your computer and use it in GitHub Desktop.

Select an option

Save jamiechalmerzlp/d0674f17c28393adfbc7c8fefc304e91 to your computer and use it in GitHub Desktop.
#Needs ExchangeOnline and MSOLService
$SharedMailboxes = Get-EXOMailbox -Filter {(recipienttypedetails -eq "SharedMailbox") -or (recipienttypedetails -eq "EquipmentMailbox") -or (recipienttypedetails -eq "RoomMailbox")} | get-MsolUser | Select-Object UserPrincipalName,blockcredential,recipienttypedetails
$SignInEnabledSharedMailboxes = $SharedMailboxes | Where-Object {$_.BlockCredential -eq $False}
$SignInEnabledSharedMailboxes | Export-CSV C:\temp\report.csv -NoTypeInformation
If ($SignInEnabledSharedMailboxes) {
Write-Host "[BAD] $($SignInEnabledSharedMailboxes.Count) shared mailboxes were found with signin enabled."
Do {
$Answer = Read-Host -Prompt 'Do you want to disable signin for all shared mailboxes? (y/n)'
If (!($Answer -match 'y' -or $Answer -match 'n')) {Write-Host 'Please answer "y" for Yes or "n" for No.'}
}
Until ($Answer -match 'y' -or $Answer -match 'n')
If ($Answer -match 'y') {
Write-Host "[GOOD] Disabling signin for all shared mailboxes."
$SignInEnabledSharedMailboxes.UserPrincipalName | ForEach-Object { Set-MsolUser -UserPrincipalName $_ -BlockCredential $true}
} Else {
Write-Host "[INFORM] Please contact the customer and resolve the issue"
}
} Else {
Write-Host "[GOOD] No shared mailboxes were found with signin enabled."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment