The Exchange 2007 Wiki

Managed Folders and Policy

Description

This script takes a CSV file and uses the entries in the columns to create managed folders and a managed folder mailbox policy. It then sets the created policy to all mailboxes.

Usage

Save the script code below into a simple text file and name it ManagedFolderSetup.msh. Open up the Exchange Management Shell and navigate to the directory containing the file you just created. Type:
.\ManagedFolderSetup.msh C:\ManagedFolders.csv
Ensure the path specified for the CSV file is correct.
Sample Script

$newManagedFolders = @()
$existingManagedFolders = @()
$managedFolderLinks = @()

## Name of the managed folder mailbox policy to be created - change this in your script
$managedMailboxPolicy = "General Policy"
if(!($args[0]))
{
 write-host "Usage: ManagedFolderSetup.msh ManagedFolders.csv"
 return
}
$data= import-csv -path $args[0]
## Create Managed folder
foreach( $i in $data )
{
   $newFolder = Get-ManagedFolder | where {$_.Name -eq $i.Folder}
   if ($newFolder -ne $null) {
        $script:existingManagedFolders += $newFolder
    } else {
        $newFolder = New-ManagedFolder -Name $i.Folder -FolderName $i.FolderName -StorageQuota $i.StorageQuota
        if($newFolder -ne $null) {
              write-host "Done"
              $script:newManagedFolders += $newFolder
         } else {
              write-host "Error: Managed folder" $i.Folder "cannot be created."
            }
      }       
}
write-host "Below Managed folders already exist:"
foreach($i in $existingManagedFolders)
{
 write-host $i.Name
 $managedFolderLinks += $i.Identity 
}
write-host "Succesfully created below Managed folders:"
foreach($i in $newManagedFolders)
{
 write-host $i.Name
 $managedFolderLinks += $i.Identity
}
## Create a Managed folder mailbox policy
$newPolicy = New-ManagedFolderMailboxPolicy -Name $managedMailboxPolicy -ManagedFolderLinks $managedFolderLinks
if ($newPolicy -ne $null) {
 write-host "Succesfully created below Managed folder mailbox policy:"
 $managedMailboxPolicy
} else {
 write-host "Error: Managed folder mailbox policy" $managedMailboxPolicy "cannot be created."
 return;
}
## Set the created managed folder mailbox policy to all mailboxes
write-host "Set the created policy to all mailboxes:"
$mailboxes = get-mailbox
foreach($mailbox in $mailboxes)
{
 $mailbox.Name
 Set-Mailbox -identity $mailbox.Identity -ManagedFolderMailboxPolicy $newPolicy.Identity
}

Disclaimer: The sample scripts are meant to serve as examples and may need modifications before they will work in your environment. The authors of the script are not responsible for any negative outcome that may result from using them. 

Site

Changes
Index
Search

 

User

 

Log In
Register

 
 

Last Modified 8/10/06 4:58 PM