The day to day ramblings of an IT Professional and Community Leader

iSCSI Virtual Disks: If you have to make a bunch… Use PowerShell!

I don’t mean to sound like a broken record but when you have to do things over and over again, it simply doesn’t make sense to do it manually. Sure, the GUI (Graphical User Interface) in Windows is great… but if you have to click through the same wizard ten times to create ten of something… well, I guess all I am saying is that PowerShell makes a lot more sense.

Last month I went through a relatively time-consuming exercise to create three LUNs on each of three Software SANs on Windows Server 2012R2. Ok great… but I then discovered that for my project I couldn’t use three LUNs of 1.5TB each… rather I needed to create nine LUNs of 500GB each. What a royal pain! By the way, seeing as I have to do this on three separate servers, my workload just tripled from doing it 9 times to doing it 27 times! This does not sound like fun.

Fortunately, I can do it all in PowerShell, which means I can save a whole lot of clicking. We are going to do this all on three different servers, named Let’s look at how:

Parameters

a) We are going to create three iSCSI Target Servers called TargetServer1, TargetServer2, and TargetServer3.

b) We are going to present the targets to five servers called InitServer1, InitServer2, InitServer3, InitServer4, and InitServer5.

c) We are going to create 9 500GB drives on each server, plus three 1GB drive on each server. In case you can’t tell, these drives will be used for nine different Failover Clusters, and the 1GB drive will be the witnesses.

d) We are going to attach all of the iSCSI Virtual Disks to the appropriate Targets.

Let’s Go!

1) Before we do anything, we want to create a session that will repeat the same tasks on each computer.

PS C:\> $session=New-PSSession –ComputerName Server1,Server2,Server3

That will save us having do do a few things over again, even though we could have done it with a simple ‘'<Up-Arrow> <Backspace>” or two.

2) We have to install the iSCSI Target Role Feature on all of these server. So:

2) The next thing we are going to do is actually create the iSCSI Targets on the three servers. By doing this with the $session that we created we will end up with three targets with the same name. I trust you will go back and fix that by hand later on. If you prefer to avoid that step though, we could bypass the $session and use the manual-PowerShell way

3) Now that we have created the Targets, we have to create the disks. Unlike the Targets (whose names will be used outside of their own servers), I don’t mind if the names of the actual disks on each server.

Warning: This script is going to take a ridiculously long time. That is because when creating the virtual disks, PowerShell is zeroing out all of the bits. This is the safer way to do things if you are re-using your disks. If they are brand new clean disks, then you can add the switch –DoNotClearDatato your statements. However unless you are in a real hurry, I would take the extra time.

4) Our disks have been created, but we have to attach them to the Targets. So:

So if we did it properly, we should now have three software SANs (Targets) with nine virtual disks each, that are each connected to three iSCSI targets, which are in turn each presented to five iSCSI initiators. Additionally, we have three ‘Quorum Disks’ on each Target.

In my next article, I will show you what needs to be done on the initiator side to get these all going for your Failover Clusters. Until then… Happy scripting!