Skip to content

Instantly share code, notes, and snippets.

@vexx32
Created June 22, 2018 18:49
Show Gist options
  • Save vexx32/a972cf7cc939dbcc1b46810fe4e89102 to your computer and use it in GitHub Desktop.
Save vexx32/a972cf7cc939dbcc1b46810fe4e89102 to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[ValidateNotNull()]
[PSCredential]
$Credential = [System.Management.Automation.PSCredential]::Empty,
[Parameter(Position = 1)]
[ValidateNotNull()]
[uri]
$ConnectionUri = 'https://outlook.office365.com/powershell-liveid/'
)
$SessionInformation = @{
ConfigurationName = 'Microsoft.Exchange'
ConnectionUri = $ConnectionUri
Credential = $Credential
Authentication = 'Basic'
AllowRedirection = $true
}
$Session = New-PSSession @SessionInformation
Import-PSSession $Session
$RecordList = Get-Mailbox -ResultSize Unlimited |
Where-Object EmailAddresses -like 'smtp:*hiddenforsecurityofclient.com' |
Select-Object -Property DisplayName, @{
Name = "EmailAddresses"
Expression = {
$_.EmailAddresses |
Where-Object {$_ -like "smtp:*hiddenforsecurityofclient.com"}
}
}
foreach ($Record in $RecordList) {
Write-Verbose "Removing Alias $($Record.EmailAddresses) for $($Record.DisplayName)"
Set-Mailbox $Record.DisplayName -EmailAddresses @{
Remove = $Record.EmailAddresses
}
}
$RecordList = Get-Mailbox -ResultSize Unlimited |
Where-Object EmailAddresses -like "smtp:*hiddenforsecurityofclient.com" |
Select-Object DisplayName, @{
Name = "EmailAddresses"
Expression = {
$_.EmailAddresses |
Where-Object {$_ -like "smtp:*hiddenforsecurityofclient.com"}
}
}
foreach ($Record in $RecordList) {
Write-Verbose "Removing Alias $($Record.EmailAddresses) for $($Record.DisplayName)"
Set-Mailbox $Record.DisplayName -EmailAddresses @{
Remove = $Record.EmailAddresses
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment