VMware Cloud Community
FreddyFredFred
Hot Shot
Hot Shot
Jump to solution

How to certain disable iSCSI paths

I have a few hosts with an iSCSI initiator and several luns from a couple different SANs. I'm trying to find as way to disable selected paths but can't get anything to work by piecing together what I've found online.

I don't mind hard coding a target or vmbha number and running the script a few times.

If you refer to the attached picture, I need to disable certain targets for a given runtime name. In this example, I need to disable targets ending in .72 or .172 on all the C0 paths and disable all the .71 and .171 targets on the C1 paths. (for a different array thre will be different IPs but the C0/C1 stuff remains the same)

pastedImage_1.png

To do it manually it's easy as I just sort by runtime name and then look at the target field and disable accordingly but doing it via powercli is proving elusive for me.

The only thing I can guarantee is the IP address in the target and the C0/C1 part of the runtime name. Everything else might change, ie. the order of the paths.

Anyone ever do something like this before and can share some code?

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Would something like this do the trick?

Note this is only for C0 and IP ending in 71.

$esxName = 'MyEsx'

foreach($hba in Get-VMHostHba -VMHost $esxName -Type IScsi){

    foreach($path in Get-ScsiLun -Hba $hba | Get-ScsiLunPath){

        if($path.Name -match "^$($hba.Device):C0:" -and $path.ExtensionData.Transport.Address -match "71:3260$"){

            Set-ScsiLunPath -ScsiLunPath $path -Active:$false -Confirm:$false

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Would something like this do the trick?

Note this is only for C0 and IP ending in 71.

$esxName = 'MyEsx'

foreach($hba in Get-VMHostHba -VMHost $esxName -Type IScsi){

    foreach($path in Get-ScsiLun -Hba $hba | Get-ScsiLunPath){

        if($path.Name -match "^$($hba.Device):C0:" -and $path.ExtensionData.Transport.Address -match "71:3260$"){

            Set-ScsiLunPath -ScsiLunPath $path -Active:$false -Confirm:$false

        }

    }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
FreddyFredFred
Hot Shot
Hot Shot
Jump to solution

Yes indeed! That works! I just copy/pasted the IF statement to do all the combos I wanted and had to put the full ip address as it seemed to disable more paths for one particular SAN since I think the match was picking up more than I wanted.

Thank you very much. You saved me a ton of manual clicks Smiley Happy

0 Kudos
FreddyFredFred
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

I've been using your code quite successfully but I've run into a little issue. When I add a new datastore it takes a long time to go through all the paths again when I want to target just 1 datastore on each host to disable certain paths.

In looking around the best I can come up with is maybe modifying the if statement to add a $path.extensiondata.lun -match and then hard coding the value what I find manually by running this little snipnet of code:

$temp = Get-ScsiLun -Hba $hba | Get-ScsiLunPath

$temp.extensiondata.lun

Am I missing something to be able to easily target just 1 datastore on a given host to disable certain paths?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If we assume a "standard" use of LUN and datastore, meaning only 1 extent (LUN) per datastore, then yes, your code should do the trick.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos