Create a clustered file share on MSCS using Perl

Here's a script that uses the Microsoft cluster automation API to create a file share on a cluster. The script specifies the cluster name, the share name, and the drive letter. The only requirement is that the drive letter is indeed clustered.

The script enumerates the cluster resources within each resource group, finds the Physical Disk resource for our drive letter, creates the file share resource, and makes the share dependant on that disk resource (so that the file share goes online after the disk comes online).

use Win32::OLE('in');
#find the group that contains the Physical disk we're looking for
foreach $resourceGroup (in $cluster->{ResourceGroups}){
 foreach $resource (in $resourceGroup->{Resources}){
   foreach $partition (in $resource->{Disk}->{Partitions}){
    if(lc($partition->{DeviceName}) eq lc($drive)){
     #now that you found the cluster group with the correct drive, you can create a share
     $newFileShare=$resourceGroup->{Resources}->CreateItem("$shareName","File Share",0);
     #add the disk as a dependency of the share


Anonymous said...

This doesn't work on my workstation. Any idea why?

Brian Seltzer said...

Well, I guess there are two main requirements for the script to run. 1) You gotta have Perl :) and 2) You have to install the administrative tools (adminpak.msi) which contains the cluster api. What error are you getting?

Anonymous said...

I installed admin pack and it started working. Thanks!

Post a Comment

Related Posts Plugin for WordPress, Blogger...