Skip to content

Instantly share code, notes, and snippets.

@fr0gger03
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fr0gger03/ab5eced3c44f56cf611f to your computer and use it in GitHub Desktop.
Save fr0gger03/ab5eced3c44f56cf611f to your computer and use it in GitHub Desktop.
PowerCLI: script to map VMFS datastore (block only) to underlying LUN using NAA ID
# you must connect and authenticate to a vCenter server
# use Connect-VIServer to do so
# establish Export file name
$csvname = Read-Host 'Please provide the file path and name for your CSV export'
# Gather information on all datastores in the vCenter and enter a loop
get-datastore |foreach-object {
# Capture the name of the datastore in a variable
$ds=$_.Name
# For each datastore, get teh information on the SCSI LUN,
# select specific properties and export it all to the CSV file
# note - the "gu" command is shorthand for "get-unique" -
# this is necessary as datastores will be reported by multiple virtual machines
get-scsilun -datastore $ds | Select-Object @{n='NAA';e={$_.canonicalname}}, @{n='Datastore Name';e={$ds}} | gu | Export-CSV "c:\users\rfw614\Desktop\scsilun.csv” -NoTypeInformation –Append
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment