Share via


PowerShell Script to Add a Disk to Host Cluster in SCVMM 2012

We all know adding a Disk to the host Cluster involves a lot of steps and we all want to simplify it using PowerShell. Here is the script.

All you need to do is specify the cluster name, the name of the disk, and size.

Import-Module virtualmachinemanager 
Import-Module FailoverClusters 
 $JobGroupID = [Guid]::NewGuid().ToString() 
# TASK1 ### create a lun on Cluster level 
$clustername = Read-Host "Enter the Clustername (some cases you might have to type FQDN on the Cluster" 
$name =  Read-Host " Enter the name of the Disk" 
$size = Read-Host " Enter the size of the LUN in TB" 
$provision = Read-Host " Thin or Thick -  Type full word" 
$hostGroup = Read-host "Host Group the Cluster belongs to " 
  
$size = 1048576 * "$size" 
$newLun = New-SCStorageLogicalUnit -StoragePool $pool -DiskSizeMB $size -Name $name -Description "" -ProvisioningType $provision 
  
$hostGroup = Get-SCVMHostGroup  -Name $hostGroup 
Set-SCStorageLogicalUnit -StorageLogicalUnit $newLun -VMHostGroup $hostGroup 
} 
$clustername = $clustername  
$hostCluster = Get-SCVMHostCluster -Name $clustername 
$newLogicalUnits = @() 
$newLogicalUnits += Get-SCStorageLogicalUnit  -Name $name 
Register-SCStorageLogicalUnit -JobGroup  $JobGroupID -StorageLogicalUnit $newLogicalUnits 
  
$logicalUnit = Get-SCStorageLogicalUnit -Name $name 
Mount-SCStorageDisk -StorageLogicalUnit $logicalUnit -MasterBootRecord -JobGroup $JobGroupID -VolumeLabel "" -QuickFormat -CreateClusterSharedVolume 
  
Set-SCVMHostCluster -Description "" -RunAsynchronously -VMHostCluster $hostCluster -JobGroup $JobGroupID -ClusterReserve "1"