Category Archives: Scripts

Creating a cluster with PowerShell

I’m obviously so late with this post that others (Jan Egil Ring) have posted about this already. Considering he’s running a blog about Powershell, his script most likely looks a lot better than mine too…

Below is the script I used at TechEd in Berlin to create my 2-node cluster. You can watch the video from TechEd if you’re interested in knowing more about clustering. It’s Symon Perryman, PM from Microsoft that does most of the talking. I’m the demo guy 🙂

Note that in this script a lot of the information is hardcoded, such as nodenames, iscsi-information and ip-addresses. I’m working on a version which will ask you for the needed information but I haven’t finished it yet, this ought to get you started though.


cls
write-host -foreground red "CREATING A 2-NODE CLUSTER WITH POWERSHELL`n`n"
sleep 3
#Start iSCSI
write-host "STARTING iSCSI SERVICE ON NODE FS01"
sleep 1
icm fs01 -scriptblock {set-service msiscsi -startuptype automatic}
icm fs01 -scriptblock {start-service msiscsi}
write-host "STARTING iSCSI SERVICE ON NODE FS02"
sleep 1
icm fs02 -scriptblock {set-service msiscsi -startuptype automatic}
icm fs02 -scriptblock {start-service msiscsi}

#Connect disks
write-host -foreground red "`nCONFIGURING iSCSI CONNECTIONS`n`n"
icm fs01,fs02 -scriptblock {iscsicli qaddtargetportal 10.10.10.20}
icm fs01,fs02 -scriptblock {iscsicli persistentlogintarget iqn.clu02-quorum T * * * * * * * * * * * * * * * 0}
icm fs01,fs02 -scriptblock {iscsicli persistentlogintarget iqn.clu02-storage T * * * * * * * * * * * * * * * 0}
icm fs01,fs02 -scriptblock {iscsicli qlogintarget iqn.clu02-quorum}
icm fs01,fs02 -scriptblock {iscsicli qlogintarget iqn.clu02-storage}
#Partition and format
write-host -foreground red "`NPARTITIONING AND FORMATTING DISKS`N`N"
icm fs01 -scriptblock {sc $env:tempdiskpart.txt @"
list disk
select disk 1
online disk
att disk clear readonly
clean
create partition primary
format fs=ntfs quick
assign letter=q
select disk 2
online disk
att disk clear readonly
clean
create partition primary
format fs=ntfs quick
assign letter=s
"@ -encoding ascii}
icm fs01 -scriptblock {diskpart /s $env:tempdiskpart.txt}
#Install feature
write-host "`NINSTALLING FAILOVER-CLUSTER FEATURE`n`n"
icm fs01,fs02 -scriptblock {load-mo -install Failover-Clustering}
#Create cluster
write-host -foreground red "`nCREATING CLUSTER`n`n"
New-Cluster FileCluster01 -Node fs01,fs02 -staticaddress 192.168.0.111
#Add disks
write-host -foreground red "`nADDING DISKS TO CLUSTER`n`n"
Get-ClusterAvailableDisk | Add-ClusterDisk