Create Storage Group (Perl)

This code can be found in Chapter 6 of Exchange Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# This script was originally published in the Exchange Cookbook,
# (http://www.exchangebookcook.com). Written by Paul Robichaux, 
# Missy Koslosky, and Devin Ganger. Redistributed with permission 
# of the publisher, O'Reilly & Associates.

# This script creates a new storage group on the specified server

# ------ SCRIPT CONFIGURATION ------

use Win32::OLE;

$strComputerName = '<serverName>';
# "batman"
$strSGName = '<storageGroupName>';
# e.g. "New Storage Group"
# ------ END CONFIGURATION ---------

$theServer = Win32::OLE->new('CDOEXM.ExchangeServer');
$theSG = Win32::OLE->new('CDOEXM.StorageGroup');
$theServer->DataSource->Open($strComputerName);

# Get the array list of StorageGroups, then coerce it to get the first
# SG name
$theSGArr = $theServer->StorageGroups;
$theFirstSG = theSGArr(0);

# stuff our new SG name into the URL
$strTemp = VBS::Mid($theFirstSG, (index($theFirstSG, 'CN', 1) + 1));
$strTargetSG = 'LDAP://' . $theServer->DirectoryServer . '/CN=' . $strSGName . ',' . $theFirstSG;

# saving the new SG object to this URL actually creates the SG
$theSG->DataSource->SaveTo($strTargetSG);
print "New SG $strTargetSG created\n";

package VBS;
use strict;
sub Mid {
  my($substr, $start, $len) = @_;
  $start--;
  return defined $len ? substr($substr, $start, $len) :
                        substr($substr, $start);
}

This code has been viewed 701 times.

New from the creators of TechTasks.com: StatSheet.com