The Exchange 2007 Wiki

Using XML configuration files in PowerShell scripts

It is very easy to create a XML config file and use it in a PowerShell Script. Here is an example to show how to configure a MailBox server.
Let assume we want to create 3 storage groups with one mailbox database in each. We also want to configure a specific filter for each Mailbox database.
We can create a XML as following :

<confMBX>
 <Filters> 
  <Filter Name="Prohibit send quota">
   <ProhibitSendQuota>300MB</ProhibitSendQuota>
  </Filter>
 </Filters>
 <StorageGroups>
  <StorageGroup Name="SG1">
   <SystemFolderPath>R:\SG1</SystemFolderPath>
   <LogFolderPath>S:\Log-SG1</LogFolderPath>
   <MDBName>MDB1</MDBName>
   <EdbFilePath>R:\SG1\MDB1\MDB1.edb</EdbFilePath>
   <CreatePF>T</CreatePF>
  </StorageGroup>
  <StorageGroup Name="SG2">
   <SystemFolderPath>R:\SG2</SystemFolderPath>
   <LogFolderPath>S:\Log-SG2</LogFolderPath>
   <MDBName>MDB2</MDBName>
   <EdbFilePath>R:\SG2\MDB2\MDB2.edb</EdbFilePath>
  </StorageGroup>
  <StorageGroup Name="SG3">
   <SystemFolderPath>R:\SG3</SystemFolderPath>
   <LogFolderPath>S:\Log-SG3</LogFolderPath>
   <MDBName>MDB3</MDBName>
   <EdbFilePath>R:\SG3\MDB3\MDB3.edb</EdbFilePath>
  </StorageGroup>
 </StorageGroups>
</confMBX>

 

This config file can be used in a script :

# setting global parameters
$hostname = hostname

# Reading the config file
$xml = [xml]$(get-content MBX_config.xml)

# Loop on StorageGroup
foreach ($sg in $xml.confMBX.StorageGroups.StorageGroup)
{
 # create the Storage Group with a specific Path for log files
 new-StorageGroup -Server:$hostname -Name:$sg.Name -LogFolderPath:$sg.LogFolderPath -SystemFolderPath:$sg.SystemFolderPath

 # Create the MailBox Database and Mount it
 new-mailboxdatabase -StorageGroup:$sg.Name -Name:$sg.MDBName -EdbFilePath:$sg.EdbFilePath | mount-database

 # Setting up the filter for this DataBase
 foreach($filter in $xml.Filters.Filter)
 {
  if ($filter.Name -eq "Prohbit Send Quota")
  {
   set-mailboxdatabase $SG.MDBName  -ProhibitSendQuota:$filter.ProhibitSendQuota
  }
 }
}

Site

Changes
Index
Search

 

User

 

Log In
Register

 
 

Last Modified 10/31/06 12:29 AM