Setting MPIO to Failover for Witness else LQD via PowerShell

Software-based VM-centric and flash-friendly VM storage + free version

Moderators: anton (staff), art (staff), Max (staff), Anatoly (staff)

Post Reply
GiveitAGo
Posts: 5
Joined: Tue Dec 05, 2023 4:10 pm

Wed Jul 10, 2024 7:28 pm

Hi All,

Posting here as I hope it helps.

I have been faffing with powershell to get from ISCSI Target IQN to Disk.
A bit more coding and I can pull Disk Serial.
A bit more coding and I can match Disk Serial to mpclaim Disk Number.
Now with a bit of extra code its possible programatically
  • to set ISCSI Targets with "witness" in their ISCSI IQN to MPIO Policy Failover
  • to set ISCSI Targets without to MPIO Policy Least Queue Depth
Boris Yurchenko asked if anyone solves this to let him know. If staff at Starwind could pass on to Boris for review that would be great! I'd happily accept a special 3x node license thank you for all the saved Starwind Staff finger and RSI clicking pain (re: Don’t break your fingers with hundreds of clicks)

Code: Select all

# Convert to Hash: MPIO Disk Info 
$disks_MPIO = (gwmi -Namespace root\wmi -Class mpio_disk_info).driveinfo | Group-Object SerialNumber -AsHashTable -AsString

$disks_starwind = Get-PhysicalDisk | Where FriendlyName -like "*Starwind*" |  Select-Object Friendlyname, UniqueID, @{Name='MPIO Name'; Expression={ ($disks_MPIO[$_.UniqueID]).Name }} | Format-Table -AutoSize

$disks_Serial_vs_ISCSI = Get-IscsiConnection | Select -Property InitiatorAddress,TargetAddress,@{Name='Session'; Expression={($_|Get-IscsiSession).TargetNodeAddress}},@{Name='DiskSerial'; Expression={($_|Get-Disk).SerialNumber}} | Group-Object -Property DiskSerial 

# Output For Review 
Write-Output ($disks_Serial_vs_ISCSI | Select -ExpandProperty Group )


$disks_Serial_vs_MPIO = @()
foreach($currDisk in $disks_Serial_vs_ISCSI){
    
    $countIsWitness = 0
    foreach($currISCSI_Target in $currDisk.Group){        
        If($currISCSI_Target.Session -like "*witness*"){
            ++$countIsWitness 
        } 
    }

    $disks_Serial_vs_MPIO += [pscustomobject]@{
        DiskSerial     = $currDisk.Name 
        MPIO_Required  = If($countIsWitness -gt 0){"FOO"}Else{"LQD"}        
        MPIO_DiskNb    = ($disks_MPIO[$currDisk.Name]).Name.Replace("MPIO Disk","")
        ISCSI_IQN      = $currISCSI_Target.Session 
    }
}

# For Review 
Write-Output $disks_Serial_vs_MPIO

# Before Changes 
& mpclaim -s -d

foreach($currDisk in $disks_Serial_vs_MPIO){
    $ArgumentList = ""
    If($currDisk.MPIO_Required -eq "FOO"){
        $ArgumentList = "-l -d " + $currDisk.MPIO_DiskNb + " 1”
    } Else {
        $ArgumentList = "-l -d " + $currDisk.MPIO_DiskNb + " 4”
            #mpclaim /?
            #0 = Clear the Policy
            #1 = Fail-Over Only
            #2 = Round Robin
            #3 = Round Robin with Subset
            #4 = Least Queue Depth
            #5 = Weighted Paths
            #6 = Least Blocks
            #7 = Vendor-Specific
    }
    Write-Output ("To set MPIO Load Balance Policy")
    Write-Output ("`t  TO: " + $currDisk.MPIO_Required)
    Write-Output ("`t FOR: " + $currDisk.ISCSI_IQN)
    Write-Output ("`t RUN: " + "mpclaim $ArgumentList")
    #start-process “c:\windows\system32\mpclaim.exe” -ArgumentList $ArgumentList -Wait    
}

# After Changes 
& mpclaim -s -d
yaroslav (staff)
Staff
Posts: 3505
Joined: Mon Nov 18, 2019 11:11 am

Thu Jul 11, 2024 10:52 pm

Hi,

Thank you for sharing! Please log a call with StarWind Support using 1183718 and this thread as your reference.
Post Reply