Monday, October 27, 2008

Create Managed Distribution Groups through powershell

I recently had to create 85 managed groups; groups where users manage their memembership (instead of admins). I wrote a powershell script to create the groups, mail-enable them, set the managedby attribute, and associated AD permissions.

I created an csv with the following headings:
Alias , DisplayName, ManagedBy
*The ManagedBy field must contain a DN

Add-PSSnapin Quest.ActiveRoles.ADManagement
[array]$group_info = import-csv "C:\group_info.csv"
$group_info ForEach-Object {
$gname = $_.dispname
$gdesc = $gname
$gAlias = $_.Alias
$gsam = $gAlias
$gmanager = $_.managedby
$gmanager = "CN=De Las Heras\, Teo,CN=Users,DC=Company,DC=org"
#For Debugging, write out the variables (tab delimited)
# Write-Host $gname, `t,$gAlias, `t, $gmanager
$objOU = [ADSI]"OU=Groups,DC=Company,DC=ORG"
$gcn = "cn=" + $gname
$objGroup = $objOU.Create("group", $gcn)
$objGroup.Put("sAMAccountName", $gsam)
$objGroup.Put("groupType", "-2147483646")
$objGroup.Put("description", $gdesc)
$objGroup.Put("displayName", $gname)
$objGroup.Put("mailnickname", $gsam)
$objGroup.put("managedby", $gmanager)
add-qadpermission -service 'servername' $gname -Account 'Company\tdelasheras' -Rights 'WriteProperty' -Property 'Member'

Tuesday, October 21, 2008

Powershell - Get status of Exchange databases

The Exchange Management Shell (EMS) provides a way to output the status of Exchange Databases through the command, get-mailboxdatabase. Note that you must include the -status switch in order to get the proper output.
get-mailboxdatabase select Mounted - will give you nothing.
The correct command is
get-mailboxdatabase -status Select Name, Mounted, LastFullBackup

I have a small script I wrote that get's the status of all the databases in my organization and sends me an e-mail if a database is dismounted. I have the script running as a scheduled task. Here it is:
**Save this a a .ps1 file ** It'll need to be signed as well

function Send-Mail
$SmtpClient = new-object
$MailMessage = New-Object
$SmtpClient.Host = 'relayserver'
$mailmessage.from = ''
$mailmessage.Subject = $sbj
$mailmessage.IsBodyHtml = 1
$mailmessage.Body = $msg
$mailmessage.Body = $msg

function exch-status {
get-mailboxdatabase -status %{$DBName = $_.Name; $DBMounted = $_.Mounted; $DBBackup = $_.LastFullBackup}

if ($DBMounted -eq $False )
$Message = "The database $DBName is unmounted. Please page Sys Admin immediately."
Send-Mail 'Exchange DB Unmounted' $Message ''
$DateToday = Get-Date
if($ -lt $
Message = "It's been 24 hours since a full backup completed successfully."
Send-Mail 'Full Backup has not run' $Message ''

****End of Script ****

Saturday, October 18, 2008

Windows 2008 Step-by-Step Guides

Exchange Availability Service

Free/Busy Tutorial:

The availability serive replaced the free/busy PF from Exchange 2003. To see how many availability services exist:

Basically, Exchange publishes the availability service through a Service Connection Point in Active Directory. The location of the Service Connection Point is in the serviceBindingInformation attribute on the following object:
CN=DC1,CN=Autodiscover,CN=Protocols,CN=DC1,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Litware Inc,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=litwareinc,DC=com

Test the Exchange Availability Service:
Test-OutlookWebServices -TargetAddress:

If the service is not functioning, it's easy to rebuild:

Exchange 2007 - Healthy Configuration

Exchange 2007 System Requirements (note: Page File should be RAM + 10 MB):

Memory Requirements (note: minimum memory / # of storage groups):

Steps to mitigate excessive paging: