StoreVirtual Storage
1752815 Members
6269 Online
108789 Solutions
New Discussion

Using powershell to set iSCSI targets and HP DSM Round Robin policy in Windows 2012

 
Erick Arturo Perez
Frequent Advisor

Using powershell to set iSCSI targets and HP DSM Round Robin policy in Windows 2012

I am amazed at what you can do with powershell on Windows 2012. The goal of this post is to share a simple script that will:

 

1- Connect to a Lefthand VIP portal via iSCSI

2- Get my windows 2012 network interfaces that I named "Storage01 and Storage02"

3- Set a variable with the initial part of the LH IQN

4- Set an array variable with the LUNs presented by LH (only two for simplicity)

5- Make the iscsi connections to the LH VIP (3 storage nodes). Setting persistance and MPIO values.

6- After connecting the iscsi LUNs then proceed to print on screen the default policy of the connections which is "none" or "vendor specific" so you know what was it before changes.

7- Set via WMI the default policy of "Round Robin" on the connections.

Credits of the WMI goes to:

http://fractostratus.wordpress.com/2012/05/14/connecting-mpio-iscsi-targets-via-powershell-and-a-bit-of-dirty-vbscript/

 

Notes:

I have 2 nics for iscsi in each node.

I have 4 Win2012 nodes.

I need to setup over 60 iSCSI volumes, so I saved a billion clicks in the Windows 2012 GUI per node

I have only tested this on Windows 2012.

I am using HP DSM

 

 

$LH_VIP ="172.128.172.100"
"Connecting Target Portal $LH_VIP"
New-IscsiTargetPortal –TargetPortalAddress $LH_VIP

"Get Networks Cards Named StorageXX Where XX is a number starting with 01"
$iscsiNICS = Get-NetIPAddress –AddressFamily IPv4 -InterfaceAlias Stor*

$tIQN = "iqn.2003-10.com.lefthandnetworks:storage-cluster:"
$tLUN = @("141:cl01-vm-001","143:cl01-vm-exch01")

foreach ($objItem in $tLUN) {
"Connecting to LUN $tIQN$objItem "
Connect-IscsiTarget -InitiatorPortalAddress $iscsiNICS[0].IpAddress -IsPersistent $True -IsMultipathEnabled $True -NodeAddress $tIQN$objItem
Connect-IscsiTarget -InitiatorPortalAddress $iscsiNICS[1].IpAddress -IsPersistent $True -IsMultipathEnabled $True -NodeAddress $tIQN$objItem
}

"Querying and Setting default MPIO Policy to Round Robin"
$MPIOPolicy = (“Non-Selected”,”Failover Only”,”Round Robin”,”Round Robin with Subset”,”Least Queue Depth”,”Weighted Paths”,”Least Blocks”)
$Policies = get-wmiobject -namespace ROOT\WMI -class DSM_QueryLBPolicy_V2
foreach($Policy in $Policies){
$Instance = $Policy.InstanceName
$objShare = Get-WmiObject -Namespace ROOT\WMI -Class DSM_LB_Operations | where{$_.InstanceName -eq $Instance}
$InParams = $objShare.GetMethodParameters(“DsmSetLoadBalancePolicyALUA”)
Write-Host Current Policy is $MPIOPolicy[$policy.LoadBalancePolicy.LoadBalancePolicy] for $policy.InstanceName$policy.LoadBalancePolicy.LoadBalancePolicy = 2
"Changing policy from old value to Round Robin" $InParams.LoadBalancePolicy = $Policy.LoadBalancePolicy $Inparams1 = $InParams.LoadBalancePolicy $Inparams1.LoadBalancePolicy = 2 $Inparams.LoadBalancePolicy = $Inparams1 $outparams = $objShare.DsmSetLoadBalancePolicy($inparams.LoadBalancePolicy) If ($outparams.Status = 2){Write-Host Policy Set to $MPIOPolicy[$Inparams1.LoadBalancePolicy]} }

 

Hope you like it!

 

1 REPLY 1
Ravi_K
HPE Pro

Re: Using powershell to set iSCSI targets and HP DSM Round Robin policy in Windows 2012

Hi Erick

 

Thanks for sharing the information

 

Regards

Ravi

Accept or Kudo