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)
$objGroup.setinfo()
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
{
Param($sbj,$msg,$to,[switch]$html)
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = 'relayserver'
$mailmessage.from = 'fromme@company.com'
$mailmessage.To.add($to)
$mailmessage.Subject = $sbj
if($html)
{
$mailmessage.IsBodyHtml = 1
$mailmessage.Body = $msg
}
else
{
$mailmessage.Body = $msg
}
$smtpclient.Send($mailmessage)
}

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 'copmpanyops@company.com'
}
$DateToday = Get-Date
if($DBBackup.day -lt $DateToday.day)
{
Message = "It's been 24 hours since a full backup completed successfully."
Send-Mail 'Full Backup has not run' $Message 'copmpanyops@company.com'
}
}

exch-status
****End of Script ****

Saturday, October 18, 2008

Windows 2008 Step-by-Step Guides

http://www.microsoft.com/downloads/details.aspx?FamilyID=518d870c-fa3e-4f6a-97f5-acaf31de6dce&DisplayLang=en#filelist

Exchange Availability Service

Free/Busy Tutorial:
http://blogs.msdn.com/deva/archive/2008/10/13/tutorial-free-busy-data.aspx

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

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 -id:user1@contoso.com -TargetAddress: user2@contoso.com

If the service is not functioning, it's easy to rebuild:
Remove-autodiscovervirtualdirectory
New-Autodiscovervirtualdirectory

Exchange 2007 - Healthy Configuration

Exchange 2007 System Requirements (note: Page File should be RAM + 10 MB):
http://technet.microsoft.com/en-us/library/aa996719.aspx

Memory Requirements (note: minimum memory / # of storage groups):
http://technet.microsoft.com/en-us/library/bb738124(EXCHG.80).aspx

Steps to mitigate excessive paging:
http://blogs.technet.com/mikelag/archive/2008/10/17/steps-to-help-mitigate-excessive-paging-and-working-set-trimming-issues.aspx