VMware Cloud Community
Ivy_Yang
Contributor
Contributor
Jump to solution

how to change "display name" via PowerCLI command?

Hi, guys,

I have a question:

Vcenter----->home---->inventory--->host and Clusters, I select an ESX host and ------->configuration----->storage adapter, we can see many LUNs from storage.

1.jpg

We usually right click the "Name" to change the name to match with what we see in stroage side.

file:///E:/1.jpg

now we present 90 LUNs to this ESX cluster.

I am wondering if there is any command we can change the device name?

I tried get-ScsiLun.....and I can get the HLU, but there is no "Name" in the outpur.........

would you help please point the right command?

many thanks in advance!

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You're nearly there, but that method requires 2 parameters.

Something like this

$esxName = "vh0034msg01.active.tan" 
$esx
= Get-VMHost $esxName
$storSys
= Get-View $esx.ExtensionData.ConfigManager.StorageSystem Get-ScsiLun -VMHost $esxName -LUNType disk -CanonicalName "naa.6006016061902e0062f2319d68e5e111" | %{   $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid, $_.DisplayName + " test") }


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

View solution in original post

11 Replies
Ivy_Yang
Contributor
Contributor
Jump to solution

actually I tried "UpdateScsiLunDisplayName" but does not work

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $esxName = “vh0034msg01.active.tan”

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $esx = Get-VMHost $esxName | Get-View

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> $storSys = Get-View $esx.ConfigManager.StorageSystem

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-ScsiLun -VMHost $esxName -LUNType disk -CanonicalName "naa.6006016061902e0062f2319d68e5e111" |foreach {$_.RuntimeName,$_.Extensiondata.DisplayName}

vmhba1:C0:T0:L10

DGC Fibre Channel Disk (naa.6006016061902e0062f2319d68e5e111)

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-ScsiLun -VMHost $esxName -LUNType disk -CanonicalName "naa.6006016061902e0062f2319d68e5e111" | %{ $storSys.UpdateScsiLunDisplayName($_.DisplayName + " test") }

Cannot find an overload for "UpdateScsiLunDisplayName" and the argument count:"1".

At line:1 char:136

+ Get-ScsiLun -VMHost $esxName -LUNType disk -CanonicalName "naa.6006016061902e

0062f2319d68e5e111" | %{ $storSys.UpdateScsiLunDisplayName <<<< ($_.DisplayName

+ " test") }

    + CategoryInfo          : NotSpecified: (:) [], MethodException

    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're nearly there, but that method requires 2 parameters.

Something like this

$esxName = "vh0034msg01.active.tan" 
$esx
= Get-VMHost $esxName
$storSys
= Get-View $esx.ExtensionData.ConfigManager.StorageSystem Get-ScsiLun -VMHost $esxName -LUNType disk -CanonicalName "naa.6006016061902e0062f2319d68e5e111" | %{   $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid, $_.DisplayName + " test") }


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

Ivy_Yang
Contributor
Contributor
Jump to solution

:smileysilly:it works!!hiahai  thanks! 

Reply
0 Kudos
KFM
Enthusiast
Enthusiast
Jump to solution

Sorry to revive an old thread but I don't know if I'm going crazy or something has changed in 2017....but it looks like $_.DisplayName is no longer a property of a ScsiLun object?

Having said that I'm trying to achieve something similar to this (and a lot of other posts on this forum) but can't seem to work it out. Basically I want to rename the SCSI LUN Display Name property to match that of the datastore name. I can't seem to find a common property that links the two together.

I can't find a reference to the datastore name in the ScsiLun object to use as a argument to UpdateScsiLunDisplayName. Conversely there is no canonical name in a datastore object returned from Get-Datastore.

Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

It's part of $_.Extensiondata.DisplayName

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
KFM
Enthusiast
Enthusiast
Jump to solution

Ok cool - I got that, thanks! Smiley Happy

Any ideas on how to solve my original problem?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The example script becomes

$esxName = "vh0034msg01.active.tan"

$esx = Get-VMHost $esxName

$storSys = Get-View $esx.ExtensionData.ConfigManager.StorageSystem

Get-ScsiLun -VMHost $esxName -LUNType disk -CanonicalName "naa.6006016061902e0062f2319d68e5e111" | %{

  $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid, $_.ExtensionData.DisplayName + " test")

}


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

Reply
0 Kudos
KFM
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

Thanks for that but that doesn't really meet what I was hoping to solve. Essentially what I'm trying to do is outlined in this blog post Renaming vSphere Datastore device display names – Cloud/Virtualisation/Automation

Any hints/tips you can pass along?

Thanks,
Kam

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You will have to change the 2nd parameter on the UpdateScsiLunDisplayName method.

In that post the author changes the name to the name of the datastore that is allocated on the LUN.

The updated script would look something like this

It will change the devicename for each LUN, that is used for the datastores starting with 'MyDS' on ESXi node 'MyEsx', to the datastorename.

As the post you refer to is doing manually.

I just tested this again on vSphere 6.5, and it works.

$esxName = 'MyEsx'

$dsName = 'MyDS*'

$dsTab = @{}

Get-Datastore -Name $dsName | %{

  $dsTab.Add($_.ExtensionData.Info.Vmfs.Extent[0].DiskName,$_.Name)

}

$esx = Get-VMHost $esxName

$storSys = Get-View $esx.ExtensionData.ConfigManager.StorageSystem

Get-ScsiLun -VMHost $esxName -LUNType disk | where{$dsTab.Keys -contains $_.CanonicalName} | %{

  $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid, "$($dsTab[$_.CanonicalName])")


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

KFM
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

Again you come through the with the goods. I knew there should be some correlation between a datastore and scsilun object but just couldn't find it. Thanks for pointing it out Smiley Happy

Thanks so much!

Cheers,
Kam

Reply
0 Kudos
pfuller_PLS
Contributor
Contributor
Jump to solution

This is a faster way to rename the "Display Name". In a CSV have a column for Name and Identifier. The Name will be the "Display Name" and the Identifier will be the naa. name. The biggest pain is matching up the naa. names to the LUNs on your storage.

Connect-VIServer -Server @("vCenter")

$myesxcli= get-VMHost vSphere_Host

$NAA = Import-csv .\VMWare_Luns.csv

$storSys = Get-View $myesxcli.ExtensionData.ConfigManager.StorageSystem

$GSL = Get-ScsiLun -VMHost $myesxcli.name -LUNType disk -CanonicalName *

Foreach ($LUN in $NAA ) {  

    $UUID = $null

    $UUID = ($GSL |Where-Object {$_.CanonicalName -eq $LUN.Identifier}).ExtensionData.Uuid

    If ($UUID) {

        write-host ("Updating " + $LUN.Identifier + " with UUID of "$UUID + " to Display name: " + $LUN.Name)

        $storSys.UpdateScsiLunDisplayName($UUID, $LUN.Name)

       

    }

   

}

Reply
0 Kudos