VMware Cloud Community
shallriseagain
Contributor
Contributor
Jump to solution

Get Active FC Path WWN of all datastores

Hello. I need to turn off one of the FC switch for maintenance. To turn off the switch smoothly, I want to set the manual path selection mode and switch all datastores to the second switch. I have a lot of datastores, so I wanted to create a csv file in which I could see invofrmation to be sure that I did not miss anything: For example:

Host         | Datastore | Active Target 192.168.1.2  | DS-01     | 21:00:00:1b:32:8f:d0:a5 

Unfortunately, all that I found on the Internet and tried to do it myself is to get HBAName, Target and State. I dont know how to comapre HBAName like "vmhba1:C0:T4:L1" with Identifier of Datastore and convert this to Datastore Name in one csv file.

Please, halp 🙂

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, in that case try with the (much) slower cmdlets.

Get-Datastore -PipelineVariable ds |

where{$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess } |

Get-ScsiLun -PipelineVariable lun |

Get-ScsiLunPath |

where{$_.Preferred} |

Select @{N='VMHost';E={$lun.VMHost.Name}},

    @{N='Datastore';E={$ds.Name}},

    ScsiLun,LunPath,SanId


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

View solution in original post

18 Replies
LucD
Leadership
Leadership
Jump to solution

Does this help?

Get-VMHost | ForEach-Object -Process {

    $esxcli = Get-EsxCli -VMHost $_.Name -V2

    $esxcli.storage.core.device.list.Invoke() |

    where{$_.IsSharedClusterwide -and $_.DeviceType -eq 'Direct-Access' -and $_.IsLocal -ne 'true'} |

    ForEach-Object -Process {

        $device = $_

        $esxcli.storage.core.path.list.Invoke() |

        where{$_.State -eq 'active' -and $_.Device -eq $device.Device} |

        Select @{N='Host';E={$esxcli.VMHost.Name}},

            @{N='Datastore';E={$device.DisplayName}},

            @{N='RuntimeName';E={$_.RuntimeName}},

            @{N='PathState';E={$_.State}},

            @{N='WWNN';E={$_.TargetTransportDetails.Split(' ')[1]}},

            @{N='WWPN';E={$_.TargetTransportDetails.Split(' ')[3]}}

    }

}


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

Reply
0 Kudos
a_p_
Leadership
Leadership
Jump to solution

To turn off the switch smoothly, I want to set the manual path selection mode and switch all datastores to the second switch.

Please don't mind me asking, but what's the reason for this? Did you have issues in the past?

What type/model of storage system do you use, and which path policy (PSP) is in place for the LUNs?

I've been working with FC environments for years (different switches, different storage vendors), and never had any issues, neither with updating firmware, reboots for other reasons, switch replacements, ...

If at least one path to the target remains active, you shouldn't need to manually switch paths.

André

Reply
0 Kudos
shallriseagain
Contributor
Contributor
Jump to solution

Thank you for reply!

I'm sorry, I incorrectly asked a question. They are all active.

Also i have a 4 paths

50:00:00:e0:da:7c:01:20

50:00:00:e0:da:7c:01:21

50:00:00:e0:da:7c:01:30

50:00:00:e0:da:7c:01:31

They are all active. I need to find Preffered Active Path of datastore and target WWN of this Path.

Also in your script i got datastore name like:  FUJITSU Fibre Channel Disk (naa.600000e00d29000000293c0100020000)"

It`s possible to change it to Fujitsu-01-Vol01 For example how I see it in the vCenter?

Reply
0 Kudos
shallriseagain
Contributor
Contributor
Jump to solution

Yes, i have a trouble in the past. If I turn off the Brocade, and the active path went through it, then it will take a little time to rebuild to another path, and I will get a small lag of I/O operations.

I have a lot of datastores like Fujitsu, HP, and self-assembly Supermicro storages.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you try like this?

Get-VMHost | ForEach-Object -Process {

    $esxcli = Get-EsxCli -VMHost $_.Name -V2

    $esxcli.storage.core.device.list.Invoke() |

    where{$_.IsSharedClusterwide -and $_.DeviceType -eq 'Direct-Access' -and $_.IsLocal -ne 'true'} |

    ForEach-Object -Process {

        $device = $_

        $dsName = $esxcli.storage.vmfs.extent.list.Invoke() |

            where{$_.DeviceName -eq $device.Device} |

            select -ExpandProperty VolumeName

        $esxcli.storage.nmp.path.list.Invoke() |

            where{$_.Device -eq $device.Device -and $_.PathSelectionPolicyPathConfig -match 'preferred: yes'} |

        Select @{N='Host';E={$esxcli.VMHost.Name}},

            @{N='Datastore';E={$dsName}},

            @{N='RuntimeName';E={$script:rt = $_.RuntimeName; $script:rt}},

            @{N='CanonicalName';E={$device.Device}},

            @{N='WWNN';E={($esxcli.storage.core.path.list.Invoke() |

                where{$_.DeviceDisplayName -eq $dsName -and $_.RuntimeName -eq $script:rt}).TargetTransportDetails.Split(' ')[1]}},

            @{N='WWPN';E={($esxcli.storage.core.path.list.Invoke() |

                where{$_.DeviceDisplayName -eq $dsName -and $_.RuntimeName -eq $script:rt}).TargetTransportDetails.Split(' ')[3]}}

    }

}


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

shallriseagain
Contributor
Contributor
Jump to solution

hmm.

Now it looks like

Host          : 10.234.1.129

Datastore     : IBM-SSD-SCST

RuntimeName   : vmhba2:C0:T4:L0

CanonicalName : eui.3639343936643533

WWNN          :

WWPN          :

 

Also, a lot of records has no names in Datastore string =(

Host          : 10.234.1.129
Datastore     : IBM-SSD-SCST
RuntimeName   : vmhba2:C0:T4:L0
CanonicalName : eui.3639343936643533
WWNN          :
WWPN          :
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, in that case try with the (much) slower cmdlets.

Get-Datastore -PipelineVariable ds |

where{$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess } |

Get-ScsiLun -PipelineVariable lun |

Get-ScsiLunPath |

where{$_.Preferred} |

Select @{N='VMHost';E={$lun.VMHost.Name}},

    @{N='Datastore';E={$ds.Name}},

    ScsiLun,LunPath,SanId


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

shallriseagain
Contributor
Contributor
Jump to solution

Very slow, but works like a charm. Thank you so much, you saved my day 🙂
Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Hello LucD,

 

I try to export in csv file but the file generated is empty. I don't know why the information is not output ?

 

Get-Datastore -PipelineVariable ds |

where{$_.Type -eq 'VMFS' -and $_.ExtensionData.Summary.MultipleHostAccess } |

Get-ScsiLun -PipelineVariable lun |

Get-ScsiLunPath |

where{$_.Preferred} |

Select @{N='VMHost';E={$lun.VMHost.Name}},

@{N='Datastore';E={$ds.Name}},

ScsiLun,LunPath,SanId |

Export-csv -Path "D:\collectInfo.csv" -NoTypeInformation -UseCulture

 

regards,

David

 

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is there output when you leave out the Export-Csv?


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Hello LucD,

Yes. A csv file is generated at the end of the script by this command

Export-csv -Path "xxx\xxxx\xxxx.csv" -NoTypeInformation -UseCulture

But the csv file is empty without information.

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That si not what I meant.
Is any output produced when you leave out the EXport-Csv?


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Such as?

If you mean something produced when you open then close the CSV file the answer is nothing appears.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, when you run the code form Solved: Re: Get Active FC Path WWN of all datastores - VMware Technology Network VMTN

Without your Export-Csv line


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

Ok I understand.

 

Nothing appears on Window Powercli.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then you obviously don't have FC LUNs that are returned by this code, hence the empty CSV


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

Reply
0 Kudos
David2021
Contributor
Contributor
Jump to solution

For information, all my Datastores get Fiber Channel attachement. I can see vmhba on each ESXi servers with a number of devices representing all Datastores.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That might be true, but note that there is a Where-clause in that code.
It only shows LUNs that are used for shared, VMFS datastores.


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

Reply
0 Kudos