VMware Cloud Community
avarcher
Commander
Commander
Jump to solution

new-datastore using runtime name

Hi

I know the runtime name - vmhba2:0:0:201 and I would like to create a VMFS datastore on it using PowerCLI. In the past I'm sure I could use this runtime name for the path parameter, however today I need the canonical name.

So either 1) how to create the datastore with the info I have, or 2) how to get the canonical name from the runtime name would help me greatly.

Thanks, Andy.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Or everything in one go

$esxName = <hostname>
$runtimeName = "vmhba2:0:0:201" 
$dsName
= "MyDS"
$esx
= Get-VMHost -Name $esxName
$lun = Get-ScsiLun -VmHost $esx | where {$_.RuntimeName -eq $runtimeName} New-Datastore -VMHost $esx -Path $lun.CanonicalName


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

View solution in original post

0 Kudos
6 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Andy,

you can get the CanonicalName from the Runtime name with:

$RuntimeName = "vmhba2:0:0:201"
(Get-VMHost | `

Get-ScsiLun | `

Where-Object {$_.RunTimeName -eq $RunTimeName} | `

Select-Object -First 1).CanonicalName


Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership
Jump to solution

Or everything in one go

$esxName = <hostname>
$runtimeName = "vmhba2:0:0:201" 
$dsName
= "MyDS"
$esx
= Get-VMHost -Name $esxName
$lun = Get-ScsiLun -VmHost $esx | where {$_.RuntimeName -eq $runtimeName} New-Datastore -VMHost $esx -Path $lun.CanonicalName


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

0 Kudos
avarcher
Commander
Commander
Jump to solution

Hi Robert,

Thanks for this, unfortunately it doesnt seem to work. The object returned by  Get-ScsiLun does not seem to have a RunTimeName property...

[vSphere PowerCLI] C:\> $lun = Get-VMHost | Get-ScsiLun
[vSphere PowerCLI] C:\> $lun | gm


   TypeName: VMware.VimAutomation.ViCore.Impl.V1.Host.Storage.Scsi.ScsiLunImpl

Name                 MemberType Definition
----                 ---------- ----------
ConvertToVersion     Method     T ConvertToVersion[T]()
Equals               Method     bool Equals(System.Object obj)
GetHashCode          Method     int GetHashCode()
GetType              Method     type GetType()
IsConvertableTo      Method     bool IsConvertableTo(type toType)
ToString             Method     string ToString()
BlocksToSwitchPath   Property   System.Nullable`1[[System.Int32, mscorlib, V...
CanonicalName        Property   System.String CanonicalName {get;}
CapacityMB           Property   System.Nullable`1[[System.Int64, mscorlib, V...
CommandsToSwitchPath Property   System.Nullable`1[[System.Int32, mscorlib, V...
ConsoleDeviceName    Property   System.String ConsoleDeviceName {get;}
ExtensionData        Property   System.Object ExtensionData {get;}
HostId               Property   System.String HostId {get;}
Id                   Property   System.String Id {get;}
Key                  Property   System.String Key {get;}
LunType              Property   System.String LunType {get;}
Model                Property   System.String Model {get;}
MultipathPolicy      Property   VMware.VimAutomation.ViCore.Types.V1.Host.St...
SerialNumber         Property   System.String SerialNumber {get;}
Uid                  Property   System.String Uid {get;}
Vendor               Property   System.String Vendor {get;}
VMHost               Property   VMware.VimAutomation.ViCore.Types.V1.Invento...
VMHostId             Property   System.String VMHostId {get;}

I'm using ESXi 4.1 ...

PowerCLI Version
----------------
VMware vSphere PowerCLI 4.1 build 264274

Cheers, Andy.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You need the latest version of PowerCLI

PS C:> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware vSphere PowerCLI 4.1 U1 build 332441


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

0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Hi Andy,

it looks like the RuntimeName is a new property of the ScsiLunImpl object in PowerCLI 4.1U1.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
avarcher
Commander
Commander
Jump to solution

Hi Robert / Luc

Great answers, sorted it for me 100%. Thanks.

Cheers, Andy.

0 Kudos