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');
$clusterName="myClusterName"; $drive="e:"; $shareName="myShare";
$cluster=Win32::OLE->new("MSCluster.Cluster"); $cluster->Open($clusterName);
#find the group that contains the Physical disk we're looking for foreach $resourceGroup (in $cluster->{ResourceGroups}){ foreach $resource (in $resourceGroup->{Resources}){ if($resource->{Disk}->{Partitions}){ 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 $newFileShare->{Dependencies}->AddItem($resource); $newFileShare->{privateProperties}->CreateItem("ShareName",$shareName); $newFileShare->{privateProperties}->CreateItem("Path","$drive\\$shareName"); $newFileShare->{privateProperties}->SaveChanges; $newFileShare->Online(5); }}}}}
3 comments:
This doesn't work on my workstation. Any idea why?
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?
I installed admin pack and it started working. Thanks!
Post a Comment