VMware Cloud Community
wetnose88
Enthusiast
Enthusiast
Jump to solution

how to Rename "displayName" via PowerCLI command

uuid,DisplayName
naa.60000970000120001295533030303031,PowerMax_odd_system_device
naa.60000970000120001297533030303031,PowerMax_even_system_device

$csv = import-csv "$env:USERPROFILE\Input\testrename.csv"

$esx = "mytest.com"
$storSys = Get-View $esx.ConfigManager.StorageSystem
Foreach ($item in $csv){
$uuid = $item.uuid
$newname = $item.DisplayName
Get-ScsiLun -VMHost $esx -LUNType disk -CanonicalName $uuid | %{
$storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid,$newname)
}
}

 

Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:4 char:21
+ $storSys = Get-View $esx.ConfigManager.StorageSystem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Perhaps try like this

 

#****************************************************************
$csv = import-csv "$env:USERPROFILE\Input\testrename.csv"

$esx = Get-VMHost -Name "mytest.com"
$storSys = Get-View $esx.ExtensionData.ConfigManager.StorageSystem
Foreach ($item in $csv){
   $uuid = $item.uuid
   $newname = $item.DisplayName
   Get-ScsiLun -VMHost $esx -LUNType disk -CanonicalName $uuid | %{
     $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid,$newname) 
   }
}

 


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

View solution in original post

7 Replies
wetnose88
Enthusiast
Enthusiast
Jump to solution

wetnose88_0-1697212899120.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Perhaps try like this

 

#****************************************************************
$csv = import-csv "$env:USERPROFILE\Input\testrename.csv"

$esx = Get-VMHost -Name "mytest.com"
$storSys = Get-View $esx.ExtensionData.ConfigManager.StorageSystem
Foreach ($item in $csv){
   $uuid = $item.uuid
   $newname = $item.DisplayName
   Get-ScsiLun -VMHost $esx -LUNType disk -CanonicalName $uuid | %{
     $storSys.UpdateScsiLunDisplayName($_.ExtensionData.Uuid,$newname) 
   }
}

 


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

wetnose88
Enthusiast
Enthusiast
Jump to solution

Hi LucD,

Can you please remove the real ESXi host name in you reply, I noticed that and changed it already to $esx = "mytest.com"

Thanks

Reply
0 Kudos
wetnose88
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

The script worked, but get some error, it rename two of the LUNs in my csv successfully to $newname

Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:4 char:21
+ $storSys = Get-View $esx.ConfigManager.StorageSystem
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-View], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You missed the ExtensionData part in my code


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

Reply
0 Kudos
wetnose88
Enthusiast
Enthusiast
Jump to solution

Thanks a lot for your quick response and helps, tested working without errors now!

Reply
0 Kudos