We have been searching all over and cannot find the correct commands to pull what we are searching for. Hopefully someone can help.
If you log into vCenter and Goto Configuration / Storage / Right click on a Datastore and click properties. Then click Manage Paths. Under Fibre Channel there is a Target: value. How do we pull that value from PowerCLI? Thank you so much for your help!
In the vSphere Client you see the Node and the Port WWN concatenated together.
To get the same output, use this
$report = foreach($esx in (Get-VMHost | where{$_.PowerState -eq "PoweredOn"})){ foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk)){ Get-ScsiLunPath -ScsiLun $lun | `
Select @{N="Host";E={$esx.Name}}, @{N="LUN";E={$lun.CanonicalName}}, @{N="Target";E={ "{0:x} {1:x}" -f ($_.Extensiondata.Transport.NodeworldwideName, $_.Extensiondata.Transport.PortworldwideName) }} } } $report | fl
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try it like this
foreach($esx in Get-VMHost){ foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk)){ Get-ScsiLunPath -ScsiLun $lun | `
Select @{N="Host";E={$esx.Name}}, @{N="LUN";E={$lun.CanonicalName}}, @{N="Target";E={$_.SanId}} } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD thank you for your reply. When I try to run your example code I am getting an error. I think it's because the variable $esx and possibly $lun are not properly defined but I am very green on this scripting so I am not 100% sure how to fix the error.
I really appriactate the help!
Are you connected to the vCenter ?
Did you do a Connect-VIServer before running the script ?
Could you perhaps show the error message(s) you see ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes I am connected to our vCenter server. The error is "Object reference not set to an instance of an object"
Normally an error message includes the line of code where the error happened, could you include the complete error message ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It wasn't in the error message but I think it was the first line. foreach($esx in Get-VMHost)
From where did you run the script ? The PowerCLI prompt, PowerGui,... ?
Does this produce an error message ?
Get-VMHost
Or is there perhaps an ESX(i) that is not powered on ?
Change the original script like this and see if it still produces the error message ?
foreach($esx in (Get-VMHost | where{$_.PowerState -eq "PoweredOn"})){ foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk)){ Get-ScsiLunPath -ScsiLun $lun | `
Select @{N="Host";E={$esx.Name}}, @{N="LUN";E={$lun.CanonicalName}}, @{N="Target";E={$_.SanId}} } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Same error on the new code. I am running this from within PowerGUI and yes I can run Get-VMhost without any errors. Let try to get another set of eyes on this and see if I can get to the bottom of the error.
OK we were able to get the script to run in PowerGUI and PowerCLI I was trying to run it orignially via PowerGUI Script Editor no idea why it was failing there but moving on. Now we are seeing the columns and target is getting us some of what we want. But it is only the first half of the target that you see in vCenter.
On another note we're having trouble making Get-ScsiLunPath to run. Following this guide http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Get-ScsiLunPath.html
If I use
$scsilun = Get-ScsiLun -VMHost 10.23.123.100 -LunType disk Get-ScsiLunPath $scsilun
PowerCLI displays
cmdlet Get-ScsiLunPath at command pipeline position 1
Supply values for the following parameters:
ScsiLun[0]:
No idea what it is looking for here.
The problem I suspect you are seeing is that the OBN (Object By Name) does not work with IP addresses.
In fact the Get-VMHost cmdlet doesn't work with an IP address, it requires a hostname.
You can do a simple reverse lookup like this
$IP = "10.23.123.100"
$hostname = ([System.Net.Dns]::GetHostEntry($IP)).HostName Get-ScsiLun -VmHost $hostname -LunType disk | Get-ScsiLunPath
Don't forget the pipeline (|) between both cmdlets.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
In the vSphere Client you see the Node and the Port WWN concatenated together.
To get the same output, use this
$report = foreach($esx in (Get-VMHost | where{$_.PowerState -eq "PoweredOn"})){ foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk)){ Get-ScsiLunPath -ScsiLun $lun | `
Select @{N="Host";E={$esx.Name}}, @{N="LUN";E={$lun.CanonicalName}}, @{N="Target";E={ "{0:x} {1:x}" -f ($_.Extensiondata.Transport.NodeworldwideName, $_.Extensiondata.Transport.PortworldwideName) }} } } $report | fl
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That works and gives us what we need!
We're trying to figure out, and this is certainly a nice to have feature, if we can get the datastore name into the output so when we send this over to the SAN team they know what we are talking about on our side. Get-Datastore |fl in the name feild is what we are hoping for.
Sure, try it like this
$report = foreach($esx in (Get-VMHost | where{$_.PowerState -eq "PoweredOn"})){ $ds = $esx.ExtensionData.Datastore | %{Get-View $_} foreach($lun in (Get-ScsiLun -VmHost $esx -LunType disk)){ Get-ScsiLunPath -ScsiLun $lun | `
Select @{N="Host";E={$esx.Name}}, @{N="LUN";E={$lun.CanonicalName}}, @{N="Target";E={ "{0:x} {1:x}" -f ($_.Extensiondata.Transport.NodeworldwideName, $_.Extensiondata.Transport.PortworldwideName) }}, @{N="Datastore";E={ ($ds | where{ $_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName}}).Name }} } } $report | fl
The script will scan the extents of each datastore known on the host to see if one of the extents corresponds with the CanonicalName of the LUN.
If you have datastores with multiple extents, the same datastorename will appear with different LUNs.
If you have LUNs that are not used in a datastore (RDM disks, free LUNs), there will be no datastorename.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
We've been trying and can't seem to get that code to run. It just seems to bounce around inside the where loop and then go back up to the
Get-ScsiLun foreach loop and then repeat.
Try the following.
First all the extents from which your datastores are made
$esx = Get-VMHost MyHost
$ds = $esx.ExtensionData.Datastore | %{Get-View $_}
$ds | %{
$_.Info.Vmfs.Extent | Select DiskName
}
Then list the LUNs with
$esx = Get-VMHost MyHost
Get-ScsiLun -VmHost $esx -LunType disk | Select CanonicalName
You should see that one or more of the LUNs also appear in the list of the datastore extents.
Just to make sure, we are talking about datastores that are created on FC connected LUNs ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference