PoshCode Archive  Artifact [4c654f9b99]

Artifact 4c654f9b998f05fce3ca73c48b8b260f28302d1fb8c93e6b1e01adbb40a96aa9:

  • File Create-datastore-by-LUN.ps1 — part of check-in [1389dfb146] at 2018-06-10 13:25:17 on branch trunk — Creates a VMFS datastore via powershell by specifying the target LUN ID (user: Ed Goad size: 1170)

# encoding: ascii
# api: powershell
# title: Create datastore by LUN 
# description: Creates a VMFS datastore via powershell by specifying the target LUN ID
# version: 0.1
# type: function
# author: Ed Goad
# license: CC0
# function: New-DatastoreByLun
# x-poshcode-id: 3412
# x-archived: 2012-05-16T21:39:27
# x-published: 2012-05-14T08:48:00
#
# Modified from the original version at http://snipplr.com/view.php?codeview&id=48048
# To run: New-DatastoreByLun “myESXHost” “SANB” 9  0 “Datastore01”
#
function New-DatastoreByLun { param( [string]$vmHost, [string]$hbaId, [int]$targetId, [int]$lunId, [string]$dataStoreName )

  $view = Get-VMHost $vmHost | get-view

  $lun = $view.Config.StorageDevice.ScsiTopology | ForEach-Object { $_.Adapter } | Where-Object {$_.Key -match $hbaId} | ForEach-Object {$_.Target} | Where-Object {$_.Target -eq $targetId} | ForEach-Object {$_.Lun} | Where-Object {$_.Lun -eq $lunId}

  $scsiLun = Get-VMHost $vmHost | Get-ScsiLun | Where-Object {$_.Key -eq $lun.ScsiLun}

  New-Datastore -VMHost $vmHost -Name $dataStoreName -Path $scsiLun.CanonicalName -Vmfs -BlockSizeMB 8 -FileSystemVersion 3
}