i have loaded the vsphere powercli cmdlets and connected to my vcenter host. i would like to know how to gather lun info, similar to what you get in vsphere client on esx host under the configuration tab and the storage section , under each san hba, where you get the naa. number, the lun number, ctl num etc... is there an cmdlet or option to pull up each one of those line items? i was looking at get-scsilun or get-scsilunpath but could not figure it out, seems like get-scsilun requires me to specify a VM, i'm only interested in what the ESX host is seeing.
You can use Get-ScsiLun with an ESX(i) server.
Just do
Get-VMHost <esx-hostname> | Get-ScsiLun
For the paths you can do
Get-VMHost <esx-hostname> | Get-ScsiLun | Get-ScsiLunPath
Depending on what you want in your output, you can include additional parameters and fikters.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
those do not work i have tried them, get-vmhost refers to VMs not physical esx hosts, the ip below is the ip of the esx host in my lab.
Get-VMHost : 8/13/2010 4:29:19 PM Get-VMHost VMHost with name '192.16
8.70.134' not found, using the specified filter(s).
At line:1 char:11
+ Get-VMHost <<<< 192.168.70.134 | Get-ScsiLun
Is that the name of your ESX server ?
Can you do
Get-VMHost
It should show you in the Name property what the name is.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
whoops i was using the vcenter server ip not the esx host ip. when i issue get-vmhost it returns the ip address of my esx host so now i tried you commands but they don't seem to work?
C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> get-vmhost 192.168.70.133 | get-scsilun
Get-ScsiLun : Object reference not set to an instance of an object.
At line:1 char:39
+ get-vmhost 192.168.70.133 | get-scsilun <<<<
C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> get-vmhost 192.168.70.133 | get-scsilunpath
Get-ScsiLunPath : The input object cannot be bound to any parameters for the command either because the command does no
t take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:1 char:43
+ get-vmhost 192.168.70.133 | get-scsilunpath <<<<
C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>
The Get-VMHost cmdlet should return a VMHostImpl object.
Can you check by doing
Get-VMHost | gm
PS: gm is the alias for Get-Member
The error messages you see seem to indicate that the Get-VMHost cmdlet doesn't place an object in the pipeline.
What does
Get-VMHost 192.168.70.133 | Select *
return ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I am running a similar command to export the results to CSV file. The export is ok, but I would like to include the ESX Host name in the results and I'm scratching my head trying to figure this out?
add-pssnapin VMware.VimAutomation.Core $VIServer = Connect-VIServer -Server $Hosts = Get-VMHost $Hosts | Get-ScsiLun | Get-ScsiLunPath | Select Parent,Name,SCsiLunId,SanId #Export-Csv -Path D:\csv_file.csv -NoTypeInformation -NoClobber
You can get at the hostname from the ScsiLunId property.
Something like this
Get-VMHost $Hosts | Get-ScsiLun | Get-ScsiLunPath | `
Select @{N="Parent";E={(Get-View -Id ($_.ScsiLunId.Split('/')[0])).Name}},
Name,SCsiLunId,SanId
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD you are a champion cheers!
Hi LucD,
I'm trying to get the LUN path details by exporting in .csv file and mail to my id using below code but unsuccessful. can you help me fine tuning the code for me?
#
#
$enablemail="yes"
$smtpServer = "my.smtp.com"
$mailfrom = "LunPathInfo@my.com"
$mailto = "kris@my.com"
$filelocation=F:\Scripts\host_luns.csv
#
#
$lunpathinfo = @()
foreach ($vmhost in Get-VIServer "vCenter Name" | get-vmhost) {
$hostview = get-view $vmhost.id
$VMHostScsiLuns = $VMHost | Get-ScsiLun | Get-ScsiLunPath
$hostview.config.storagedevice.multipathinfo.lun | % { `
$lunname=$_.id
$lunpolicy=$_.policy.policy
$_.path | % {
$pathstate=$_.pathstate
$lunpaths=$VMHostScsiLuns
$lunpathinfo += "" | select @{name="Hostname"; expression={$vmhost.name}},
@{name="LunName"; expression={$lunname}},
@{name="LunPolicy"; expression={$lunpolicy}},
@{name="PathState"; expression={$pathstate}},
@{name="LUNPaths"; expression={$lunpaths}}
}
}
}
$lunpathinfo | export-csv F:\Scripts\host_luns.csv
#
#
if ($enablemail -match "yes")
{
$msg = new-object Net.Mail.MailMessage
$filelocationContent = Get-Content $filelocation
$att = new-object Net.Mail.Attachment($filelocation)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $mailfrom
$msg.To.Add($mailto)
$msg.Subject = "LUNPathInfo"
$msg.Attachments.Add($att)
$msg.IsBodyHTML = $true
$smtp.Send($msg)
}
That Get-VIServer cmdlet is from a rather old PowerCLI release.
Which PowerCLI version are you using ? Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I'm using PowerCli 4.1 & 5.1 as well in difference servers. Environment is vSphere 4.x (4.0 and 4.1) servers. Basically i'm looking for LUN information in below format.
Host Name
HBA Name
LUN #
PathSelectionPolicy
Source
Status
Target
Path
Datastore name
and How many paths that LUN has
Thanks in advance
Br,
Kris
Did you ever get this script to work? I'd like to check it out and see if it could be useful for the RDM's in my environment
Hi ,
Try this Get-VMhost esxi-13.test.com| Get-ScsiLun
PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VMhost esxi-13.test.com| Get-ScsiLun
CanonicalN ConsoleDeviceName LunType CapacityGB MultipathPolicy
ame
---------- ----------------- ------- ---------- ---------------
naa.600... /vmfs/devices/disks/naa.600... disk 1,024.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 4,096.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 4,096.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 279.365 Fixed
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 500.000 RoundRobin
naa.2ff... /vmfs/devices/disks/naa.2ff... disk 0.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 4,096.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 3,072.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 2,048.000 RoundRobin
naa.600... /vmfs/devices/disks/naa.600... disk 1,024.000 RoundRobin