Would you please help me get this script to also print the lunID and datastore name please?
$esxihosts = get-cluster Oracle | get-vmhost
foreach ($i in $esxihosts) {
$esxclihost = $i | get-esxcli
$disks = $esxclihost.storage.core.device.list()
#$fcdisks = $disks | where {$_.displayname -match "SP_SQLCLS"}
$fcdisks = $disks
foreach ($d in $fcdisks) {
#$esxclihost.storage.core.device.setconfig($false,$d.device,$true)
$esxclihost.storage.core.device.list() | where {$_.device -eq $d.device} | select device,IsPerenniallyReserved,size
__________________________
script gives:
Device IsPerenniallyReserved Size
naa.6000144000000010705b6e368ce6ff5c false 30720
but I want it to show something like:
Device lunID DataStoreName IsPerennially Reserved Size
naa.6000144000000010705b6e368ce6ff5c 5 Exchange_VMFS_01 false 30720
BTW, credit due to the owner of this blog: http://blog.pipefl.com/
cheers,
KC
Probably not the prettiest way, but this should get the job done:
$esxihosts = get-cluster Oracle | get-vmhost
foreach ($i in $esxihosts) {
$esxclihost = $i | get-esxcli
$disks = $esxclihost.storage.core.device.list()
#$fcdisks = $disks | where {$_.displayname -match "SP_SQLCLS"}
$fcdisks = $disks
foreach ($d in $fcdisks) {
#$esxclihost.storage.core.device.setconfig($false,$d.device,$true)
$esxclihost.storage.core.device.list() | where {$_.device -eq $d.device} | select Device,
@{N='LUN ID'; E={((Get-VMHost $i | Get-ScsiLun | Where {$_.CanonicalName -eq $d.Device}).RuntimeName -split ':' | Select -last 1).TrimStart('L')}},
@{N='Datastore Name'; E={(Get-VMHost $i | Get-Datastore | Where {$_.ExtensionData.Info.Vmfs.Extent.DiskName -eq $d.Device}).Name}},
IsPerenniallyReserved,
Size | Format-Table -Autosize
}
}
Thanks so much MKGuy.
Howver, running your script, I get:
_______________________________________
Device LUN ID Datastore Name IsPerenniallyReserved Size
------ ------ -------------- --------------------- ----
naa.6000144000000010705b6e368ce6ff42 false 512000
Device LUN ID Datastore Name IsPerenniallyReserved Size
------ ------ -------------- --------------------- ----
naa.6000144000000010705b6e368ce6ff4f false 40960
Device LUN ID Datastore Name IsPerenniallyReserved Size
------ ------ -------------- --------------------- ----
naa.6000144000000010705b6e368ce70018 false 51200
PowerCLI E:\scripts\PowerCLI>
I can do it in bash:
_________________
#!/bin/sh
esxcfg-scsidevs -m > /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt
#echo "loop through each DataStore"
echo "lunID Perennial_Reservation NaaID DataStore `uname -n`"
for DataStore in `cat /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt |awk '{print $5}'`
do
#check datastore's perennial reservation setting
SD_NaaID=`grep $DataStore /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt | awk '{print $1}' | cut -d: -f1`
SD_NaaID_PR=`esxcli storage core device list -d $SD_NaaID | grep "Perennially Reserved" | cut -d: -f2 | cut -d" " -f2`
lunID=`esxcfg-mpath -L | grep ${SD_NaaID}| cut -d":" -f4 | cut -d" " -f1 | sort -u | cut -c2-3`
echo "${lunID} ${SD_NaaID_PR} ${SD_NaaID} ${DataStore}"
done
naa_list=`esxcfg-mpath -l | grep "naa\." | grep "Device: " | cut -d: -f2 | sort -u`
echo "checking luns without datastores (either RDMs or new luns with no VMFS yet)..."
for naaID in `echo $naa_list` ; do
#echo "checking for RDMs with perennial reservation as false"
grep ${naaID} /tmp/esxcfg-scsidevs-m-naaID_DataStore.txt >/dev/null
RC=$?
if [ ${RC} != 0 ] ; then
lunID=`esxcfg-mpath -L | grep ${naaID}| cut -d":" -f4 | cut -d" " -f1 | sort -u | cut -c2-3`
NaaID_PR=`esxcli storage core device list -d $naaID | grep "Perennially Reserved" | cut -d: -f2 | cut -d" " -f2`
echo "${lunID} ${NaaID_PR} ${naaID} no_datastore"
fi
done
_______________________________________________________________
but PowerShell is the way forward for checking all hosts at once
and I'm gonna wrap it into an email and vCheck plugin too.
That's odd, I was able to get everything from my hosts with the most recent PowerCLI 5.8 release. What PowerCLI version are you running? Are these perhaps RDMs? RDMs don't have datastore names.
Can you execute the following for testing the individual sections?
$scsiluns = Get-Cluster Oracle | Get-VMHost | Get-ScsiLun
$scsiluns | fl
All LUNs should be listed and they should have the appropriate CanonicalName and RuntimeName properties.
$ds = Get-Cluster Oracle | Get-VMHost | Get-Datastore
$ds | ForEach | {$_.ExtensionData.Info.Vmfs.Extent}
This should list some properties including the DiskName property which is the SCSI LUN naa ID.
Try like this
$esxihosts = Get-VMHost
foreach ($esx in $esxihosts) {
$esxclihost = Get-EsxCli -VMHost $esx
$esxclihost.storage.core.device.list() | where {$_.DeviceType -eq 'Direct-Access'} |
Select @{N='ESX';E={$esx.Name}},
@{N='LUN ID'; E={$d = $_; ((Get-ScsiLun -VmHost $esx | Where {$_.CanonicalName -eq $d.Device}).RuntimeName -split ':' | Select -last 1).TrimStart('L')}},
@{N='Datastore Name'; E={$d = $_; (Get-Datastore -RelatedObject $esx | Where {$_.ExtensionData.Info.Vmfs.Extent.DiskName -eq $d.Device}).Name}},
IsPerenniallyReserved,
Size
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks again for your help. PowerCLI is 5.5.0.5836
The first command in your recent post works fine, giving the lunID within the SCSI address, perennial reservation, and lots of other stuff, excepting the datastore name.
..snip
Id :
CanonicalName :
RuntimeName :
Key :
LunType :
Model :
SerialNumber :
Vendor :
ConsoleDeviceName :
CapacityMB :
CapacityGB :
MultipathPolicy :
CommandsToSwitchPath :
BlocksToSwitchPath :
HostId :
VMHostId :
VMHost :
Uid :
IsLocal :
ExtensionData :
Id :
CanonicalName :
RuntimeName :
Key :
LunType :
Model :
SerialNumber :
Vendor :
ConsoleDeviceName :
CapacityMB :
CapacityGB :
MultipathPolicy :
CommandsToSwitchPath :
BlocksToSwitchPath :
HostId :
VMHostId :
VMHost :
Uid :
IsLocal :
ExtensionData :
PowerCLI E:\scripts\Po
...snip
The second command gives this error:
PowerCLI E:\scripts\PowerCLI> $ds | ForEach | {$_.ExtensionData.Info.Vmfs.Extent}
Expressions are only allowed as the first element of a pipeline.
At line:1 char:52
+ $ds | ForEach | {$_.ExtensionData.Info.Vmfs.Extent} <<<<
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
The first command is not supposed to contain the datastore name, it's just to extract the LUN ID of the RuntimeName value from the object with the matching CanonicalName. Since your post didn't show any values, I suppose you just omitted them on purpose?
The 2nd command I gave which is to find the datastore name mapped to a LUN naa ID had an error with a superfluous pipe after the ForEach.
It should be:
$ds | ForEach {$_.ExtensionData.Info.Vmfs.Extent}
You should be able to manually query the datastore object with the appropriate LUN naa ID like:
Get-Datastore | Where {$_.ExtensionData.Info.Vmfs.Extent.DiskName -eq 'naa.6000144000000010705b6e368ce6ff42'}
Using a filter like in Luc's example (where {$_.DeviceType -eq 'Direct-Access'}) and/or where {$_.IsOffline -eq $false} also makes sense to filter out controller and old detached devices, but shouldn't really matter.
Both, my and Luc's examples work fine for me. I guess you should walk through each individual command section to see where it goes wrong in your case.
I know how to step through the commands in bash, and run it in diag mode with the -x option, but I've not got there yet in PowerShell.
So, LucD's kind offering gives all but the Datastore Name:
PowerCLI E:\scripts\PowerCLI> .\List-Perrenial-Reservations.ps1
ESX : host1
LUN ID : 4
Datastore Name :
IsPerenniallyReserved : false
Size : 30720
ESX : host1
LUN ID : 11
Datastore Name :
IsPerenniallyReserved : false
Size : 1048576
ESX : host1
LUN ID : 10
Datastore Name :
IsPerenniallyReserved : false
Size : 10240
MKguy, putting that pipe in helps:
PowerCLI E:\scripts\PowerCLI> Get-Cluster Oracle | Get-VMHost | Get-Datastore
Name FreeSpaceGB CapacityGB
---- ----------- ----------
datastore1 1.747 2.500
datastore2 402.947 499.750
datastore3 190.577 499.750
datastore4 8.850 19.750
PowerCLI E:\scripts\PowerCLI> $ds | ForEach {$_.ExtensionData.Info.Vmfs.Extent}
DiskName Partition DynamicType DynamicProperty
-------- --------- ----------- ---------------
naa.600601606332... 3
naa.600014400000... 1
naa.600014400000... 1
Apologies for not knowing how to put this all together, does this show you why the datastore isn't reporting when I run either LucD's or MKguy's script to show both lunID and perennial reservation along with the Datastore name?
cheers again,
KC
Which PowerCLI version are you using, the Get-Datastore with the RelatedObject parameter that I use, only was introduced recently.
Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc:
PowerCLI E:\scripts\PowerCLI> Get-PowerCLIVersion
PowerCLI Version
----------------
VMware vSphere PowerCLI 5.5 Release 1 build 1295336
---------------
Snapin Versions
---------------
VMWare AutoDeploy PowerCLI Component 5.5 build 1262826
VMWare ImageBuilder PowerCLI Component 5.5 build 1262826
VMware License PowerCLI Component 5.5 build 1265954
VMware VDS PowerCLI Component 5.5 build 1295334
VMware vSphere PowerCLI Component 5.5 build 1295334
It should work in that version.
A quick test, does this return datastore objects ?
$esx= Get-VMHost -Name MyEsx
Get-Datastore -RelatedObject $esx
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PowerCLI E:\scripts\PowerCLI> $esx= Get-VMHost -Name MyEsx
Get-VMHost : 05/12/2014 09:23:00 Get-VMHost VMHost with name 'MyEsx'
was not found using the specified filter(s).
At line:1 char:17
+ $esx= Get-VMHost <<<< -Name MyEsx
+ CategoryInfo : ObjectNotFound: (:) [Get-VMHost], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
utomation.ViCore.Cmdlets.Commands.GetVMHost
Just to make sure, you did replace 'MyEsx' with the name of one of your ESXi servers ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ok. right. Thanks for your patience. Using my fully qualified hostname, the two commands you asked me to test are in fact returning the datastorenames:
Device LUN ID Datastore Name IsPerenniallyReserved Size
------ ------ -------------- --------------------- ----
naa.6000144000000010705b6e368ce6ff5c 4 false 30720
PowerCLI E:\scripts\PowerCLI> $esx = Get-VMHost -Name host1.org
PowerCLI E:\scripts\PowerCLI> Get-Datastore -RelatedObject $esx
Name FreeSpaceGB CapacityGB
---- ----------- ----------
host1_Boot 1.613 2.500
TEST_LUN_01 48.301 49.250
TEST_LUN_01 39.480 49.250
TEST_LUN_01_1 48.801 49.750
PowerCLI E:\scripts\PowerCLI>
But I can't see what's missing when I run your and Luc's scripts which call the Get-Datastore command as they both return nothing for the Datastore field.
Would you step me through how to check the next part of building up the script commands?
cheers
KC
Give it a try like this
$esxihosts = Get-VMHost
foreach ($esx in $esxihosts) {
$esxclihost = Get-EsxCli -VMHost $esx
$esxclihost.storage.core.device.list() | where {$_.DeviceType -eq 'Direct-Access'} |
Select @{N='ESX';E={$esx.Name}},
@{N='LUN ID'; E={$d = $_; ((Get-ScsiLun -VmHost $esx | Where {$_.CanonicalName -eq $d.Device}).RuntimeName -split ':' | Select -last 1).TrimStart('L')}},
@{N='Datastore Name'; E={
$d = $_
(Get-Datastore -RelatedObject $esx | Where {$_.ExtensionData.Info.Vmfs.Extent | where{$_.DiskName -eq $d.Device}}).Name}},
IsPerenniallyReserved,
Size
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
doesn't show LUN ID and also can i know how to export to CSV format?
See Re: Scrip to get Host SCSI ID ( LUN ID)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
How do I get the naa id for this script
Thanks
Madhusudan