Monday, 14 March 2011

Set-MailboxCalendarSettings Code Snippet

This code will autoupdate calendar entries and accept meeting requests automatically and delete non-calendar items

Set-MailboxCalendarSettings 
-Identity "South-Room" 
-AllowConflicts:$False 
-AddOrganizerToSubject:$True 
-AllBookInPolicy:$True 
-AllRequestInPolicy:$true 
-AutomateProcessing "AutoUpdate" 
-DeleteNonCalendarItems:$true


Thursday, 10 March 2011

Converting Mail User to Mail Enabled User With Mail Forwarding to External EMail Address (Exchange 2007)

This snippet of code will convert a MAIL USER to MAILBOX enabled user and it will store and forward emails to his external email address.


**  The code below creates a dummy mail user Greg Perth and converts it to MAIL ENABLED USER **

$pwd = Read-Host "Enter Password" -Assecurestring

New-Mailuser -Name "Greg Perth" -ExternalEmailAddress "Greg.Perth@hotmail.com" -OrganizationalUnit "Perth" -Password $pwd -UserPrincipalName "Greg.Perth@mycompanydomain.com.au" -SamAccountName "Greg.Perth"
 

$obj = Get-MailUser -id "Greg Perth"
Disable-MailUser -id "Greg Perth" -confirm:$false


  $timer = [diagnostics.stopwatch]::startnew()
  $erroractionpreference = "silentlycontinue"
  $mailboxsuccess = $false
  while (($timer.elapsed.totalseconds -lt 900) -and (!($mailboxsuccess)))
   {
   $error.clear()

   New-MailContact -Name $obj.Name -ExternalEmailAddress $obj.ExternalEmailAddress -OrganizationalUnit "PerthContacts" -Verbose:$false

   if($error.count -eq 0)
    {
    write-host "Mail Contact successfully created"
    $mailboxsuccess = $true
    }
   else
    {
    write-host "." -nonewline
    start-sleep -s 30
    }
  }
  $timer.stop()
  $erroractionpreference = "continue"
  $secs = "{0:N2}" -f ($timer.elapsed.totalseconds)
  write-host "Mail Contact Process ran for: $secs seconds."

Enable-Mailbox -id "Greg Perth" -Database "Mailbox Database" -Verbose:$false

Set-Mailbox -id "Greg Perth" -ForwardingAddress $obj.DistinguishedName  -DeliverToMailboxAndForward:$true -Verbose:$false
 

write-host "*** *** **** "
write-host "Successfully Converted Mail enabled User to Mailbox User with external mail forwarding."
write-host "*** *** ****"

Converting Mail User to Mail Enabled User (Exchange 2007)

Simple Steps to Convert Mail User to MailBox Enabled User
 
Disable-MailUser -id "MailUser Id"
Enable-Mailbox -id "MailUser Id" -Database "Mailbox Database"

NOTE: Executing the Disable-MailUser will remove all the Exchange attributes from AD for "MailUser Id"

Restart Exchange 2007 Services From Powershell

If you are troubleshooting Exchange Server 2007 than it will be good to have a look at the Services on which Exchange Server 2007 depends.

Cut-Paste the following code in Powershell to RESTART Exchange Server 2007 services on your Exchange Server.

Stop-Service MSExchangeAdTopology
Stop-Service MSExchangeAntiSpamUpdate
Stop-Service MSExchangeEdgeSync
Stop-Service MSExchangeFDS
Stop-Service MSExchangeIMAP4
Stop-Service MSExchangeIS
Stop-Service MSExchangeMailSubmission
Stop-Service MSExchangeMailboxAssistants
Stop-Service MSExchangeMonitoring
Stop-Service MSExchangePOP3
Stop-Service MSExchangeRepl
Stop-Service MSExchangeSearch
Stop-Service MSExchangeServiceHost
Stop-Service MSExchangeSA
Stop-Service MSExchangeTransport
Stop-Service MSExchangeTransportLogSearch
Stop-Service msftesql-Exchange -Force

Start-Service MSExchangeAdTopology
Start-Service MSExchangeAntiSpamUpdate
Start-Service MSExchangeEdgeSync
Start-Service MSExchangeFDS
Start-Service MSExchangeIMAP4
Start-Service MSExchangeIS
Start-Service MSExchangeMailSubmission
Start-Service MSExchangeMailboxAssistants
Start-Service MSExchangeMonitoring
Start-Service MSExchangePOP3
Start-Service MSExchangeRepl
Start-Service MSExchangeSearch
Start-Service MSExchangeServiceHost
Start-Service MSExchangeSA
Start-Service MSExchangeTransport
Start-Service MSExchangeTransportLogSearch
Start-Service msftesql-Exchange



You do not have to start the services highlighted in GREEN if you are not using POP3 or IMAP4.



After running the above code give it a 30 seconds for all the services to come up.

-------------------------------------------------------------------------------------------------
YOU CAN DO THIS WAY TOO !!


Restart-Service MSExchangeAdTopology  -Force
Restart-Service MSExchangeAntiSpamUpdate  -Force
Restart-Service MSExchangeEdgeSync  -Force
Restart-Service MSExchangeFDS  -Force
Restart-Service MSExchangeIMAP4  -Force
Restart-Service MSExchangeIS  -Force
Restart-Service MSExchangeMailSubmission  -Force
Restart-Service MSExchangeMailboxAssistants  -Force
Restart-Service MSExchangeMonitoring  -Force
Restart-Service MSExchangePOP3  -Force
Restart-Service MSExchangeRepl  -Force
Restart-Service MSExchangeSearch  -Force
Restart-Service MSExchangeServiceHost  -Force
Restart-Service MSExchangeSA  -Force
Restart-Service MSExchangeTransport  -Force
Restart-Service MSExchangeTransportLogSearch  -Force
Restart-Service msftesql-Exchange -Force  -Force

-----------------------------------------------------------------------------------------------------------
IF YOUR EXCHANGE SERVER IS UNSTABLE AFTER RESTARTING SERVICE THAN THIS CMDLET WILL MAKE SURE THAT ALL THE REQUIRED SERVICES ARE RUNNING 

Test-ServiceHealth | Select-Object -Expand ServicesNotRunning | Start-Service



------------------------------------------------------------------------------------------

Wednesday, 9 March 2011

Automating IIS installation after Installation of Windows Operating System

IIS installation can be troublesome for Server Administartors but not anymore.
If you have just installed your Windows 2003 ENT or Windows 2008 OS than you can follow the steps.
 
You will need an answere file, similar to the one below and you can save the 2 sections below as a TXT file.
 
[Components] aspnet=on
complusnetwork=on
dtcnetwork=off
bitsserverextensionsisapi=off
bitsserverextensionsmanager=off
iis_common= on
iis_ftp=off
fp_extensions=off
iis_inetmer=on
iis_nntp=off
iis_smtp=off
iis_asp=on
iis_internetdataconnector=on
sakit_web=on
tswebclient=on
iis_serversideincludes=on
iis_webdav=off
iis_www=on
appsrv_console=on
inetprint=off
 
 
[InternetServer]
SvcManualStart=www
PathFTPRoot=
PathWWWRoot=c:\Inetpub\Wwwroot
ApplicationDependency=
ExtensionFile=
DisableWebServiceOnUpgrade=True
 
(SAVE THE HIGHLIGHTED SECTION AS A TXT FILE ON THE SERVER)
(CHANGE THE SETTINGS IN THE ABOVE SECTION AS PER YOUR REQUIREMENT)

Open the command prompt on the server and type the following command
 Sysocmgr.exe /i:sysoc.inf  /u:%PathToUnattendFile%
If you still did'nt get it than look at the link below

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/80455459-01b0-4961-aeab-081ce2eb03a4.mspx