VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

You cannot call a method on a null-valued expression

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
14 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, let's try to pinpoint where the problem is exactly.
Does the following also produce that error?

$clus = "IS"

$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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, can you do the following as well?

$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

   }

}

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

   # 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]

   }

   }


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

attached the updated script

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And this version?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

You are simply superb. Thank you very much Champ Smiley Happy

Reply
0 Kudos