Powershell Create Windows 2008 R2 Cluster

Teched 2010 Berlin #TEE10 #Teched

For Demo and learning Sites you need often thing that takes only a minute but when you play with it it takes more time than you want.So with this in my mind I created 3 powershell scripts that you can use for building a cluster , NLB Cluster and a MSTDC cluster resource.So If you want to create a Cluster you can do this in the GUI or with a Powershell Script.

So make sure the disk are formatted and that Your network is ok. and if you running this script in a environment with a Windows 2003 DC with DNS. You may have to set extra security to get things working.

You can find the Scripts Here : Powershell Scripts

Powershell Create Cluster Teched 2010 Berlin #TEE10 #Teched

This Cluster creation script creates a two node cluster with a witness disk at your choice. First we do the import of the modules and add the feature for failover clusters this section you have to do this on every node. You can do this remote if you want. Or run the script on the other node and abort it on the input section.

 

#Importing Microsoft`s PowerShell-modules
Write-Host "Install System Modules" -ForegroundColor yellow
ImportSystemModules
#Add-WindowsFeature
Write-Host "Add Failover Clustering" -ForegroundColor yellow
Add-WindowsFeature Failover-Clustering
#Importing Microsoft`s PowerShell-module for administering NLB Clusters
Write-Host "Install ServerManager Modules" -ForegroundColor yellow
Import-Module ServerManager

Here we put the cluster names , netbios, clustername, IP etc.

#Variables for creating the new cluster
Write-Host "Cluster Properties Hostname / Node Names" -ForegroundColor yellow
$Clusternode1 = Read-Host "Enter ClusterNode 1 for the new cluster"
$Clusternode2 = Read-Host "Enter ClusterNode 2 for the new cluster"
$ClusterFqdn = Read-Host "Enter Cluster for the new cluster"
$ClusterIP = Read-Host "Enter cluster primary IP"
#Clear old Cluster info
Write-Host "Old Cluster Configuration Will Be ereased just to make sure" -ForegroundColor yellow
Clear-ClusterNode $Clusternode1 -force
Clear-ClusterNode $Clusternode2 -force

#Validating new cluster
Write-Host "Validate Windows 2008 R2 Cluster…" -ForegroundColor yellow
Test-Cluster $Clusternode1 -ignore network,inventory,storage

#Creating new cluster
Write-Host "Create Windows 2008 R2 Cluster…" -ForegroundColor yellow
New-Cluster -Node "$Clusternode1" -Name $ClusterFqdn -NoStorage -StaticAddress "$ClusterIP"

If you have multiple disks and you don’t know what is cluster disk 4 or 6 or what disk should be used for the Quorum disk ? Well I did make a selection that shows only the smallest disk that are available

#Show Cluster Disk Available
Write-Host "Show Cluster Disk Available…" -ForegroundColor yellow
Get-ClusterAvailableDisk
#Show Wittness Disk Capable
Write-Host "Show Wittness disk for Cluster Available…" -ForegroundColor yellow
Get-ClusterAvailableDisk | ?{ $_.Size -lt 1573741824}

Sure You can change this for not to put in “cluster disk 1” but use only the disk number.

# Place the Wittness disk
Write-Host "Choose a Wittness disk for the Windows 2008 R2 Cluster… Must be "Cluster Disk # "" -ForegroundColor yellow
$ClusterQuorumdisk = Read-Host "Enter Wittness disk Cluster Disk number"

# Add disks to the Cluster
Write-Host "Add disks to Windows 2008 R2 Cluster…" -ForegroundColor yellow
Get-ClusterAvailableDisk | Add-ClusterDisk

Here Is the mounting off the cluster disk and I put a sleep in it this way I make sure the disk is online

#Show Wittness Disk Capable
Write-Host "Show Wittness disk for Cluster Available…" -ForegroundColor yellow
Get-ClusterAvailableDisk | ?{ $_.Size -lt 1573741824}
Start-Sleep -Seconds 5
# Change the quorum model
Write-Host "Change the Quorum model Windows 2008 R2 Cluster…" -ForegroundColor yellow
Set-ClusterQuorum -NodeAndDiskMajority $ClusterQuorumdisk

The Second node is added If you have a four node cluster just add them here

Add-Clusternode $Clusternode2 ,$Clusternode3 , $Clusternode4

But you must also use the input section above

$Clusternode3 = Read-Host "Enter ClusterNode 3 for the new cluster"

$Clusternode4 = Read-Host "Enter ClusterNode 4 for the new cluster"

 

 

# Add Cluster node
Write-Host "Add Cluster node to Windows 2008 R2 Cluster…" -ForegroundColor yellow
Add-Clusternode $Clusternode2

You can find the Scripts Here : Powershell Scripts

Powershell Create Cluster 

Teched 2010 Berlin #TEE10 #Teched

Author: Robert Smit [MVP]

Robert Smit is Senior Technical Evangelist and is a current Microsoft MVP in Clustering as of 2009. Robert has over 20 years experience in IT with experience in the educational, health-care and finance industries. Robert’s past IT experience in the trenches of IT gives him the knowledge and insight that allows him to communicate effectively with IT professionals who are trying to address real concerns around business continuity, disaster recovery and regulatory compliance issues. Robert holds the following certifications: MCT - Microsoft Certified Trainer, MCTS - Windows Server Virtualization, MCSE, MCSA and MCPS. He is an active participant in the Microsoft newsgroup community and is currently focused on Hyper-V, Failover Clustering, SQL Server, Azure and all things related to Cloud Computing and Infrastructure Optimalization. Follow Robert on Twitter @ClusterMVP Or follow his blog https://robertsmit.wordpress.com Linkedin Profile Http://nl.linkedin.com/in/robertsmit Robert is also capable of transferring his knowledge to others which is a rare feature in the field of IT. He makes a point of not only solving issues but also of giving on the job training of his colleagues. A customer says " Robert has been a big influence on our technical staff and I have to come to know him as a brilliant specialist concerning Microsoft Products. He was Capable with his in-depth knowledge of Microsoft products to troubleshoot problems and develop our infrastructure to a higher level. I would certainly hire him again in the future. " Details of the Recommendation: "I have been coordinating with Robert implementing a very complex system. Although he was primarily a Microsoft infrastructure specialist; he was able to understand and debug .Net based complext Windows applications and websites. His input to improve performance of applications proved very helpful for the success of our project

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.