Files
Scripting/Powershell/PowerShell-Office365Admin/ExchangeWithAADConnect/DisableRemoteMailUser.ps1
DistractADD cfddd4fad2 Added Files
2021-07-06 13:16:46 +10:00

25 lines
775 B
PowerShell

# Disable a list of mail users
#
# What is the FQDN of the on-prem Exchange server?
$exchangeServerFQDN = ''
# What accounts are we disabling?
$usersToDisable = @('','')
# Create Exchange connection Uri from FQDN
$exchangeConnectionUri = 'http://' + $exchangeServerFQDN +'/PowerShell/'
# Establish a session to Exchange
$userCredential = Get-Credential
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $exchangeConnectionUri -Authentication Kerberos -Credential $userCredential
Import-PSSession $session -DisableNameChecking -AllowClobber
# Get list of mailboxes
foreach ($userToDisable in $usersToDisable) {
Disable-RemoteMailbox -Identity $userToDisable -Confirm:$false
}
# End the Exchange Session
Remove-PSSession -Session $session