Archive

Posts Tagged ‘Exchange Server 2010’

Changelog: Set-Exchange2010Features.ps1

November 27th, 2009 No comments

This is the changelog page for Set-Exchange2010Features.ps1. You will find a complete list of released versions, their dates, and the features and issues addressed in each. Please refer to the script’s main page for more information including download links, installation details, and more.

v3-3 – 12-29-2011

  1. bug fix: option 99, to exit, didn’t work.
  2. bug fix: CAS options were missing asp.net and ISAPI filters
  3. feature added: Adobe PDF filter pack is now a separate menu option

v3.2 – 12-23-2011

  1. added Web-WMI Windows Feature to all Client Access Server (CAS) role requirements as this is now a requirement in SP2
  2. Changed latest update download to SP2

v3.0

  1. swapped out some functions for newer versions
  2. added transcript
  3. general code cleanup

v2.2

  1. Cleaned up code for detecting R2 version so that it doesn’t bomb with service packs.
  2. cleaned up some other items so that the Lync prerequisite script and this script are more similar.

v2.1

  1. Cleaned up menu code; Cleaned up code to disable IP v6;

v2.0 – 05-07-2010

  1. better detection of installed filter packs; uses Filter Pack 2; includes PDF iFilter pack; added disabling TCP/IP V6 option.
  2. Now uses BITS for file transfers; added unzip function to unzip the PDF iFilter pack download. Cleaned up some functions. Uses environmental
  3. variable “temp” for download location. Checks if things are already installed/downloaded/unzipped before trying to install/download/unzip them.

v1.1 – 04-09-2010

  1. added help; downloads of update rollups; cleanup of variables; added another option for typical install w/o RPC-Over-HTTP
  2. added RunOnce to delete download path on reboot

v1.0 – 11-27-2009

  1. initial version

Script: Add-BadPhrasesFromFile.ps1 – Importing a File of Bad Words and Phrases into the Content Filter in Exchange Server 2010

November 8th, 2009 No comments

Description

Once upon a time, we didn’t have to worry about our sensitive eyes seeing offensive words in emails. Times have changed, and now we have some built-in features to help prevent us from seeing terms and phrases that might be deemed offensive. Exchange has had the capacity to define a list of words that are considered bad, and bounce messages if it comes across a message containing any.

But that can take quite a while to manually add each one to the Content Filter, especially if you’re starting out with a long list of words you’d like to filter for. If that’s the case, PowerShell to the rescue! We can use Get-Content to open a text file, and then a ForEach loop to cycle through each line, adding each to the content filter phrase list via Add-ContentFilterPhrase. Add-ContentFilterPhrase can add words and phrases to either the GoodWord list, which will allow words through, or the BadWords list, which will get blocked.

The text file containing the words and phrases to be filtered just needs to have each word/phrase on a new line. No special formatting or anything. So if you have an existing text file, such as the sample word list previously supplied with Microsoft Forefront Security for Exchange, it will work fine. Copy this script to Notepad:

$a = hostname
If ((Get-TransportServer $a).AntispamAgentsEnabled -eq $false) {
    write-host "Please install the antivirus agents first, then rerun this script"
    exit
}
$phrases=Get-Content badwordlist.txt

if ($args[0] -ne "uninstall"){
 ForEach ($phrase in $phrases)           {
  Add-ContentFilterPhrase -Phrase $phrase -Influence BadWord
 }
}else{
 ForEach ($phrase in $phrases)           {
  write-host "Removing $phrase"
  Remove-ContentFilterPhrase -Phrase $phrase -confirm:$false
 }
}

Save that as Add-BadWordsFromFile.ps1, and your text file as badwordlist.txt in the same folder. If you’ve already installed the anti-spam agents on your transport server, then run

.\Add-BadWordsFromFile.ps1

and it will import the contents of the text file, and add them to the Content Filter. If you don’t have the anti-spam agents installed, the script will exit without trying to import the list. If you decide later that you’d like to remove the complete list from the Content Filter, just run the script again as

.\Add-BadWordsFromFile.ps1 uninstall

and it will remove those words contains in the file (preserving any other words you may have manually added).

Once the words and phrases are imported, you can view/add/remove them manually by opening Exchange Management Console and navigating to Organization Configuration>Hub Transport>Anti-spam>Content Filtering>Properties>Custom Words. You’ll see the list in the lower half of the window, as shown below:

This should make importing a list into the Content Filter a little quicker and easier. I welcome any comments.

Installation

Execution Policy: Third-party PowerShell scripts may require that the PowerShell Execution Policy be set to either AllSigned, RemoteSigned, or Unrestricted. The default is Restricted, which prevents scripts – even code signed scripts – from running. For more information about setting your Execution Policy, see Using the Set-ExecutionPolicy Cmdlet.

Donations

I’ve never been one to really solicit donations for my work. My offerings are created because *I* need to solve a problem, and once I do, it makes sense to offer the results of my work to the public. I mean, let’s face it: I can’t be the only one with that particular issue, right? Quite often, to my surprise, I’m asked why I don’t have a “donate” button so people can donate a few bucks. I’ve never really put much thought into it. But those inquiries are coming more often now, so I’m yielding to them. If you’d like to donate, you can send a few bucks via PayPal at https://www.paypal.me/PatRichard. Money collected from that will go to the costs of my website (hosting and domain names), as well as to my home lab.

Download

Add-BadPhrasesFromFile.zip

Running PowerShell Scripts via Scheduled Tasks

October 7th, 2009 No comments

The robust capabilities of PowerShell and the Exchange Management Shell allow us to streamline and automate many system tasks. By using scheduled tasks, we can now run tasks on a recurring schedule, thus reducing our manual workload, as well as providing capabilities that were not previously available.

Generally, any PowerShell task can be automated, as long as it doesn’t require manual intervention. For this example, we’ll run a script called New-UserWelcome.ps1. This script, as will be documented in a future blog post, sends a ‘welcome’ email to all new mailboxes. This blog post assumes that the script to be scheduled is error free. We’ll plan to run the script every 4 hours.

What the PowerShell script does might dictate what server you run it from. In this example, since the script will send email, we’ll run it from an Exchange 2007 hub transport server.

On a hub transport server running on Windows 2003 server, we go to Control Panel>Scheduled Tasks. Once there, right click and chose New Scheduled Task. Give the task a name and press enter. Now right click on the task and choose Properties.

In the Run field, we include the path to the PowerShell executable, as well as the path to the Exchange console file (which contains the Exchange cmdlets), and the actual script we want to run. An example would be:

c:\windows\system32\windowspowershell\v1.0\powershell.exe -psconsolefile "c:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -command "New-UserWelcome.ps1"

We also place the path to our scripts folder in the Start In field. This is because our example script, New-UserWelcome.ps1, is in the scripts folder:

"c:\program files\microsoft\exchange server\scripts"

In the Run As field, enter the name of an Exchange admin account, and click Set Password to enter the password for that account.

On the Schedule tab, set the Schedule Task to be Daily, Every 1 day, and click the Advanced button. Check Repeat Task, and set it for Every 4 hours for a duration of 24 hours. Click Ok twice.

Now we can test the scheduled task by right clicking on it and choosing Run.

In Windows 2008, the GUI is a tad different. Go to Administrative Tools>Task Scheduler. In the Action pane on the far right, click Create Basic Task. Give the task a name, and click next. Click Daily, and Next. Choose Recure every 1 day, and Next. Choose Start a program, and Next. Enter the path to PowerShell, the path to the Exchange console file, and the path to the scipe in the Program/Script field. For this example, we’ll use:

c:\windows\system32\windowspowershell\v1.0\powershell.exe -psconsolefile "c:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -command "New-UserWelcome.ps1"

In the Start In field, add the path to the \scripts folder than holds your PowerShell script, such as

"c:\program files\microsoft\exchange server\scripts"

And then click Next. When presented with the popup about arguments in the text box, click Yes. On the Summary page, click the box for Open the Properties dialog for this task when I click Finish. Then click Finish.

When the properties dialog box opens, click the triggers tab, click edit, click the Repeat task every 4 hours (you can type in the pulldown box) for a duration of 1 day. Then click Ok twice.

Once that’s done, click Run in the lower part of the Action pane to test.

As you can see, it’s not terribly complex to run scheduled PowerShell scripts. By doing so, we can automate many mundane tasks, and even add functionality that is not already there.

We will build upon this article in future articles.

Creating a Receive Connector to Use for Sending Email from PowerShell

May 19th, 2009 8 comments

Some of the PowerShell scripts I use and/or write send email to either users or myself. In order for that to work, a Hub Transport server has to allow the SMTP traffic from the script. So, we need a receive connector that will allow the email to be sent under the right conditions. Here’s how we can easily accomplish that.

I find it best to run scripts that send email right from a Hub Transport server. So we’ll create a new receive connector called “Internal Relay” using the New-ReceiveConnector cmdlet, and set it to allow mail from itself. This is done with the -RemoteIPRanges parameter. We’ll set it to 127.0.0.1, the loopback address for the server.

Since we don’t need to authenticate, we’ll set -AuthMechanism to ‘none’, and set the -PermissionsGroups to ‘AnonymousUsers’.

Last, we’ll set it to enabled, and configure which server it should be on. Remember, it needs to be on a server holding the Hub Transport role.

New-ReceiveConnector -Name "Internal Relay" -Bindings 0.0.0.0:25 -RemoteIPRanges 127.0.0.1 -AuthMechanism Tls -Enabled $true -Fqdn "myserver.mydomain.com" -PermissionGroups AnonymousUsers -Server mysever

Change the highlighted info to suit your needs. I use 127.0.0.1 if I’ll be running the scripts on the local Exchange server.

We allow anonymous users to actually relay by granting the ‘ms-Exch-SMTP-Accept-Any-Recipient’ extended right to the Anonymous Logon account using Add-AdPermission. This is done using:

Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-Exch-SMTP-Accept-Any-Recipient"

We can also grant NT Authority\Anonymous Logon the right to bypass anti-spam agents using:

Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-exch-bypass-anti-spam"

We can pipe all of the commands together into a one-liner. The finished script looks like this:

New-ReceiveConnector -Name "Internal Relay" -Bindings 0.0.0.0:25 -RemoteIPRanges 127.0.0.1 -AuthMechanism Tls -Enabled $true -Fqdn "myserver.mydomain.com" -PermissionGroups AnonymousUsers -Server mysever | Add-ADPermission -User "NT AUTHORITY\ANONYMOUS LOGON" -ExtendedRights "ms-Exch-SMTP-Accept-Any-Recipient, ms-exch-bypass-anti-spam"

This gives us a connector that we can use to send email from PowerShell. Verify it by using

Get-ReceiveConnector -Name "Internal Relay" | Get-ADPermission | ft User, ExtendedRights

In the coming posts, we’ll use this to our advantage.

Changelog: Send-NewUserWelcome.ps1

April 30th, 2009 No comments

This is the changelog page for Send-NewUserWelcome.ps1. You will find a complete list of released versions, their dates, and the features and issues addressed in each. Please refer to the script’s main page for more information including download links, installation details, and more.

v1.3 – 09-03-2011

  1. HTML formatted email
  2. PowerShell 2.0 code
  3. Comment Based Help
  4. application event log logging
  5. install function for creating scheduled task

v1.2 – 03-27-2010

  1. use registry for last run info
  2. variable cleanup

v1.1 – 05-01-2009

v1.0 – 04-30-2009

  1. Original version

Cool E14 OWA Features Revealed

February 12th, 2009 No comments

Our beloved Exchange product group has released a great video on some of the features coming in OWA for E14. These included threaded conversations, embedded IM, and more. But the most anticipated feature if rich features for non Microsoft browsers including Firefox and Safari.

Microsoft is also rebranding the “Exchange Labs” service as “Outlook Live”.

Check out the info and video at http://msexchangeteam.com/archive/2009/02/12/450639.aspx