Category Archives: PowerShell

Exchange Microsoft PowerShell

Use the Exchange Management Shell to set up mail forwarding

This example delivers email to the mailbox of Douglas Kohn and, at the same time, forwards all mail sent to Douglas Kohn to douglaskohn.parents@fineartschool.net.

Set-Mailbox -Identity "Douglas Kohn" -DeliverToMailboxAndForward $true -ForwardingSMTPAddress "douglaskohn.parents@fineartschool.net"  

 

This example forwards all email sent to the mailbox of Ken Sanchez, an employee of Contoso Suites, to one of his coworkers, pilarp@contoso.com.

 
Set-Mailbox -Identity "Ken Sanchez" -ForwardingSMTPAddress "pilarp@contoso.com"
 

For detailed syntax and parameter information, see Set-Mailbox.

 

Note:
-ForwardingsmtpAddress to multiple addresses Shell script

The parameter “ForwardingSmtpAddress” only allow to setup one SMTP address.
To work around this issue, you can setup the mailbox forwarding to a distribution group, you need to add the users you want to forward message to this distribution group.

 

link:
https://docs.microsoft.com/en-us/exchange/recipients/user-mailboxes/email-forwarding?view=exchserver-2019

Exchange Microsoft PowerShell

Enable antispam functionality on Mailbox servers

Applies to: Exchange Server 2016

Topic Last Modified: 2016-03-28

Use the Install-AntispamAgents.ps1 PowerShell script to install and enable the built-in Exchange antispam agents on a Mailbox server.

The following antispam agents are available in the Transport service on Exchange 2016 Mailbox servers, but they aren’t installed by default:

  • Content Filter agent
  • Sender Filter agent
  • Sender ID agent
  • Protocol Analysis agent for sender reputation

You can install these antispam agents on a Mailbox server by using an Exchange Management Shell script, which is important if these agents are your only defense to help prevent spam. Typically, you don’t need to install the antispam agents on a Mailbox server when your organization uses other types of antispam filtering on incoming mail.

noteNote:
Although the Recipient Filter agent is available on Mailbox servers, you shouldn’t configure it. When recipient filtering on a Mailbox server detects one invalid or blocked recipient in a message that contains other valid recipients, the message is rejected. The Recipient Filter agent is enabled when you install the antispam agents on a Mailbox server, but it isn’t configured to block any recipients. For more information, see Recipient filtering procedures on Edge Transport servers.
  • Estimated time to complete this task: 15 minutes
  • You can only use PowerShell to perform this procedure. To learn how to open the Exchange Management Shell in your on-premises Exchange organization, see Open the Exchange Management Shell.
  • The Connection Filtering agent and the Attachment Filtering agent aren’t available on Mailbox servers. They’re only available on Edge Transport servers, and they’re installed and enabled there by default. However, the Malware agent is installed and enabled by default on Mailbox servers. For more information, see Anti-malware protection.
  • If you have other Exchange antispam agents operating on the messages before they reach the Mailbox server (for example, an Edge Transport server in the perimeter network), the antispam agents on the Mailbox server recognize the antispam X-header values that already exist in messages, and those messages pass through without being scanned again.
  • You need to be assigned permissions before you can perform this procedure or procedures. To see what permissions you need, see the “Transport configuration” entry in the Mail flow permissions topic.
  • For information about keyboard shortcuts that may apply to the procedures in this topic, see Keyboard shortcuts in the Exchange admin center.

 

tipTip:
Having problems? Ask for help in the Exchange forums. Visit the forums at: Exchange Server, Exchange Online, or Exchange Online Protection.

read more »

Code Snippets Active Directory PowerShell

PowerShell: Get-ADUser to retrieve password last set and expiry information

Get-ADUser -identity username -properties *
 get-aduser -filter * -properties passwordlastset, passwordneverexpires |ft Name, passwordlastset, Passwordneverexpires
get-aduser -filter * -properties passwordlastset, passwordneverexpires | sort name | ft Name, passwordlastset, Passwordneverexpires

Export the list to CSV so we can work on it in Excel. In this example we substitute, format table (ft) for select-object.

Type:

Get-ADUser -filter * -properties passwordlastset, passwordneverexpires | sort-object name | select-object Name, passwordlastset, passwordneverexpires | Export-csv -path c:\temp\user-password-info-20131119.csv

PowerShell: Get-ADUser to retrieve password last set and expiry information


read more »

Code Snippets Exchange PowerShell

Turn Exchange Anonymous Relay On or Off or View Connector Status

This EMS script for Exchange 2007-2016 allows Exchange Administrators to toggle anonymous external relay permissions on front-end Receive Connectors. Connectors listed in Yellow allow anonymous SMTP emails to any internal or external recipients. Connectors listed in White only

Toggle-ExternalRelayReceiveConnectors


C:\_tmp>.\Toggle-ExternalRelayReceiveConnectors.ps1

Toggle External Relay

1 - SRV-EXCH2\Client Frontend EXSERVER1
2 - SRV-EXCH2\Default Frontend EXSERVER1
3 - SRV-EXCH2\Outbound Proxy Frontend EXSERVER1
X - Exit

Which Receive Connector to toggle:

This EMS script for Exchange 2007-2016 allows Exchange Administrators to toggle anonymous external relay permissions on front-end Receive Connectors. Connectors listed in Yellow allow anonymous SMTP emails to any internal or external recipients. Connectors listed in White only allow SMTP emails to internal recipients. Run this script from the Exchange Management Shell.

See my blog for more information: http://www.expta.com/2016/01/turn-exchange-anonymous-relay-on-or-off.html

read more »

Code Snippets Office365 PowerShell

Office 365 : Password Sync doesn’t synchronize with Azure AD Connect

Verified password sync is disabled via using PowerShell

Following cmdlets have been used to verify above and I noticed password sync was in fact disabled although I checked the option in Azure AD connect setup.

Import-Module ADSync
Get-ADSyncAADPasswordSyncConfiguration -SourceConnector <‘LOCAL DOMAIN NAME>

Enabled password sync via PowerShell

Set-ADSyncAADPasswordSyncConfiguration -SourceConnector <‘LOCAL DOMAIN NAME> -TargetConnector <‘xxxxxxx.onmicrosoft.com – AAD’> -Enable $true

 

thanks to: http://www.tekronin.net/2015/10/09/office-365-woes-password-sync-doesnt-synchronize-with-azure-ad-connect/

Office 365 woes | Password Sync doesn’t synchronize with Azure AD Connect

Code Snippets Exchange Microsoft PowerShell

Export to CSV all your Exchange 2007/2010 Email Addresses

If you want to export all your users email addresses to a CSV so you can see who has which alias you can do this with this Power Shell Command


Get-Mailbox -ResultSize Unlimited
|Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses
|Where-Object {$_.PrefixString -ceq “smtp”}
| ForEach-Object {$_.SmtpAddress}}}
| Export-CSV c:\smtp.csv -NoTypeInformation

I have wrapped it here so just paste it in to Power Shell to run and this will show the Primary Email address and then all the alias addresses.

http://unlockpowershell.wordpress.com/2010/01/27/powershell-get-mailbox-display-smtp-addresses/
http://cscmblog.blogspot.pt/2012/02/export-to-csv-all-your-exchange.html