VMware Cloud Community
SureshKumarMuth
Commander
Commander

Finding Lun details using powercli

Hi,

I want to extract lun details from all hosts connected to a particular vcenter server. I found the following article, however it talks about one cluster, what modification is needed to run at vcenter level without providing cluster name as a parameter

LUN report - datastore, RDM and node visibility - LucD notes

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
17 Replies
LucD
Leadership
Leadership

You could run the function against all clusters in your vCenter.

Something like this

Get-Cluster | %{

    .\Cluster-LUN-List.ps1 $_.Name

}


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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander

Hi,

I tried executing the script and got following error

The property 'ClusterName' cannot be found on this object. Verify that the

property exists and can be set.

At C:\TEMP\Cluster-LUN-List.ps1:61 char:2

+     $lun.ClusterName = $clusName

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

The property '129' cannot be found on this object. Verify that the property

exists and can be set.

At C:\TEMP\Cluster-LUN-List.ps1:64 char:3

+         $lun.$esxName = "ok"

+         ~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

The property 'CanonicalName' cannot be found on this object. Verify that the

property exists and can be set.

At C:\TEMP\Cluster-LUN-List.ps1:65 char:27

+         if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}

+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

The property 'UsedBy' cannot be found on this object. Verify that the propert

exists and can be set.

At C:\TEMP\Cluster-LUN-List.ps1:66 char:20

+         if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}

+                          ~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

    + FullyQualifiedErrorId : PropertyNotFound

The property 'SizeMB' cannot be found on this object. Verify that the propert

exists and can be set.

At C:\TEMP\Cluster-LUN-List.ps1:67 char:20

+         if(!$lun.SizeMB){$lun.SizeMB = $_.Value[2]}

+                          ~~~~~~~~~~~~~~~~~~~~~~~~~

do I need any specific version or powercli to run this script ?

Regards,

Suresh

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership

No, but it looks like the Add-Type didn't work.

Could you eventually attach the .ps1 file you are calling?

There might have been some copy/paste issues


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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander

Attached the script.

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership

Ok, which PowerShell version are you suing?

Display the content of $PSVersionTable

Did you see the following as the first error?

add-type.png


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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander

PowerCLI C:\TEMP> $PSVersionTable

Name                           Value

----                           -----

PSVersion                      4.0

WSManStackVersion              3.0

SerializationVersion           1.1.0.1

CLRVersion                     4.0.30319.34014

BuildVersion                   6.3.9600.16394

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}

PSRemotingProtocolVersion      2.2

Did you see the following as the first error?

I could not grab that info while running, can you let me know how can I redirect the error message to a file to check that please.

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership

You can send the output to a text file.

Start-Transcript -Append -Path C:\Temp\output.txt

Get-Cluster | %{

    .\Cluster-LUN-List.ps1 $_.Name 2>&1 | Write-Output

}

Stop-Transcript


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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander

Attached output file

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership

Looks like a funny character slipped in during the copy/paste of the code.

The following line seems to indicate that

Invalid token '129' in class, struct, or interface member declaration

Try with the attached .ps1 file instead


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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander

Attached new output file. Still could not run.

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership

Do you happen to have ESXi nodes that have an IP address as the hostname?


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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander

No, we have only two hosts in the VC and none of them has IP as the hostname.

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership

What does this return?

Get-Cluster -Name CLuster01 | Get-VMHost


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

Reply
0 Kudos
SureshKumarMuth
Commander
Commander

It returns the IP address of the ESXi hosts, one thing I forgot to mention, the hosts are connected using IP to VC instead of hostname. Would that cause this issue ?

Regards,
Suresh
https://vconnectit.wordpress.com/
Reply
0 Kudos
LucD
Leadership
Leadership

Yes, that is why we see the 129 error.

It takes that name,splits on the dot and takes the first qualifier, which is obviously 129.

Try the attached, slightly adapted version.

Also note that the machine where you run this needs .Net 3.5 to be installed (due to the Add-Type the script is using).


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

Reply
0 Kudos
bigjohn1989
Contributor
Contributor

Hey LuCD,

The script is failing due to my hosts have a - in the name.

Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

Its failing when it tries to run the add-type command. it doesnt like a - in the type definition. is there away around this issue?

PS C:\git> Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

Add-Type : c:\Users\AppData\Local\Temp\1\bp1zm0ly.0.cs(6) : Invalid token '-' in class, struct, or interface member declaration

c:\Users\AppData\Local\Temp\1\bp1zm0ly.0.cs(5) : public string SizeMB;

c:\Users\AppData\Local\Temp\1\bp1zm0ly.0.cs(6) : >>>  public string****-****;

c:\Users\AppData\Local\Temp\1\bp1zm0ly.0.cs(7) :      public string*****-****;

At line:1 char:1

+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef -Ignore ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception

    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand

Thank you, 904-633-1876 Johnathan Colleton – Virtualization & Provisioning System Administrator
Reply
0 Kudos
LucD
Leadership
Leadership

In the comments of my LUN Report – Datastore, RDM And Node Visibility post, there are a couple of solutions for that issue.


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

Reply
0 Kudos