Hi,
please help as I am getting the below error,
You cannot call a method on a null-valued expression.
At D:\myreports\Free_LUNs_Info.ps1:54 char:11
+ $key = $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Index operation failed; the array index evaluated to null.
At D:\myreports\Free_LUNs_Info.ps1:59 char:11
+ $scsiTab[$key] = $_.CanonicalName,"",$capacityGB,$lunId,""
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArrayIndex
Hereby attached the script
PowerCLI Version
----------------
VMware PowerCLI 11.2.0 build 12483598
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component PowerCLI Component 11.2 build 12483642
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.2 build 12483638
Ok, that is good news.
That means the script is now passing the failing line.
Now back to the original script (included the changes we just tested).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Could it be that there are no VMFS datastores on the ESXi nodes in the cluster?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There are many VMFS datastores, this script was working when we are using 5.5. After we upgraded from 5.5 to 6.5, this script is not working.
Ok, let's try to pinpoint where the problem is exactly.
Does the following also produce that error?
$esxServers = Get-Cluster $clus | Get-VMHost | Sort-Object -Property Name
$esxServers | %{
$esxImpl = $_
# Get SCSI LUNs
if(([Version]$esxImpl.Version).Major -lt 6){
$esxImpl | Get-ScsiLun | where {$_.LunType -eq "Disk"} | %{
$esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.CanonicalName.Split(".")[1]
}
}
Else{
$esxImpl.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object{$_.LunType -eq 'disk'} |%{
$esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName.Split(".")[1]
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD, here is the output
You cannot call a method on a null-valued expression.
At D:\mytest.ps1:14 char:4
+ $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At D:\mytest.ps1:14 char:4
+ $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Ok, can you do the following as well?
Get-Cluster $clus | Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$esx.ExtensionData.Config.StorageDevice.ScsiLun |
Where-Object { $_.LunType -eq 'disk' } | % {
$_ | Select @{N = 'Version'; E = { $esx.Version}}, DiskName, CanonicalName
}
}
It looks as if the issue with the CanonicalName property from the Get-ScsiLun cmdlet is fixed in vSphere 6.5.
Can you try replacing that part in the script with
$version = [Version]$esxImpl.Version
if ($version.Major -ne 6 -and $version.Minor -ne 0)
{
$esxImpl | Get-ScsiLun -LunType disk | % {
$esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.CanonicalName.Split(".")[1]
}
}
Else
{
$esxImpl.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object { $_.LunType -eq 'disk' } | % {
$esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName.Split(".")[1]
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Below is the output after I replacing
# Get SCSI LUNs
$version = [Version]$esxImpl.Version
if ($version.Major -ne 6 -and $version.Minor -ne 0)
{
$esxImpl | Get-ScsiLun -LunType disk | % {
$esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.CanonicalName.Split(".")[1]
}
}
Else
{
$esxImpl.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object { $_.LunType -eq 'disk' } | % {
$esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName.Split(".")[1]
}
}
PS D:\> .\mytest1.ps1
You cannot call a method on a null-valued expression.
At D:\mytest1.ps1:17 char:4
+ $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At D:\mytest1.ps1:17 char:4
+ $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_.DiskName. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
and if I execute the below code
$clus = "IS"
Get-Cluster $clus | Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$esx.ExtensionData.Config.StorageDevice.ScsiLun |
Where-Object { $_.LunType -eq 'disk' } | % {
$_ | Select @{N = 'Version'; E = { $esx.Version}}, DiskName, CanonicalName
}
}
I am getting the output but DiskName shows blank
Version DiskName CanonicalName
------- -------- -------------
6.5.0 naa.624a9370c377
6.5.0 naa.6006016001d0
6.5.0 naa.6006016001d0
6.5.0 naa.6006016001d0
That is strange, it shouldn't go through the else-block when the ESXi version is not 6.0.
Can you attach the updated version of the script?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The intention was to include that part of the code in the original script.
Like the attached code.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
below is the output from attached code
You cannot call a method on a null-valued expression.
At D:\New folder\mytest4.ps1:51 char:13
+ $esxImpl.ExtensionData.config.Network.DnsConfig.Hostname + "-" + $_. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Cannot index into a null array.
At D:\New folder\mytest4.ps1:65 char:13
+ $scsiTab[$key][1] = $dsName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
And this version?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Below is the output of attahed script
isesx02-624a937000002547995
isesx02-624a937000002547995
isesx02-6006016000002547995
isesx02-6006016000002547995
Cannot index into a null array.
At D:\New folder\test.ps1:66 char:13
+ $scsiTab[$key][1] = $dsName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At D:\New folder\test.ps1:67 char:13
+ $scsiTab[$key][4] = $dscName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Ok, that is good news.
That means the script is now passing the failing line.
Now back to the original script (included the changes we just tested).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are simply superb. Thank you very much Champ