VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

List to get unused disks in vCenter

Hi,

Please help to get the list of unused disks in vCenter. We have removed few RDMs and I would like to know the unused disks which is not a part of Datastores or RDMs

Please help

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can save the file I attached earlier in a file, for example Cluster-LUN.ps1.
Then you can call the function as follows (provided the file was saved in the folder where you are currently located, otherwise provide the full path)

Connect-VIServer  -Server 10.10.10.10

.\cluster-LUN.ps1 -clus abc -csvname Prod_vCenter_$date.csv


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

View solution in original post

0 Kudos
16 Replies
LucD
Leadership
Leadership
Jump to solution

Have a look at Find Free SCSI LUNs


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

I am getting the list of all the RDMs which are currently presented to the host.

But I have fews devices which are free.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

What probably happens, the free LUN are queried per ESXi node.

If the VM that has the LUN as a RDM, run on ESX1, then the LUN will be shown as free on ESX2.

An alternative script is the one I published in LUN Report – Datastore, RDM And Node Visibility

This will show for each LUN on which ESXi node it is visible, and if the LUN is allocted as a RDM to a VM, used for a Datastore or free.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

I am getting the below error when I execute the script. Attached the script which I am using.

Get-Cluster : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At D:\Free_Info.ps1:10 char:27

+ $esxServers = Get-Cluster $clusName | Get-VMHost | Sort-Object -Property Name

+                           ~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-Cluster], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster

You cannot call a method on a null-valued expression.

At D:\Free_Info.ps1:12 char:1

+ $LunInfoDef += ("ntpublic string" + ($_.Name.Split(".")[0].Replace('-','')) + "; ...

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

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

    + FullyQualifiedErrorId : InvokeMethodOnNull

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

c:\Users\adm.jmadhu\AppData\Local\Temp\laxtjbjq.0.cs(1) : >>> public struct LunInfo16398{npublic string ClusterName;

c:\Users\adm.jmadhu\AppData\Local\Temp\laxtjbjq.0.cs(2) : public string CanonicalName;

At D:\Free_Info.ps1:16 char:1

+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

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

    + CategoryInfo          : InvalidData: (c:\Users\adm.jm...ber declaration:CompilerError) [Add-Type], Exception

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

Add-Type : c:\Users\adm.jmadhu\AppData\Local\Temp\laxtjbjq.0.cs(4) : Invalid token '}' in class, struct, or interface member declaration

c:\Users\adm.jmadhu\AppData\Local\Temp\laxtjbjq.0.cs(3) : public string UsedBy;

c:\Users\adm.jmadhu\AppData\Local\Temp\laxtjbjq.0.cs(4) : >>> public string SizeMB;n}

At D:\Free_Info.ps1:16 char:1

+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

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

    + CategoryInfo          : InvalidData: (c:\Users\adm.jm...ber declaration:CompilerError) [Add-Type], Exception

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

Add-Type : Cannot add type. Compilation errors occurred.

At D:\Free_Info.ps1:16 char:1

+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

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

    + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException

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

Get-ScsiLun : Cannot validate argument on parameter 'VmHost'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At D:\Free_Info.ps1:21 char:12

+ $esxImpl | Get-ScsiLun | where {$_.LunType -eq "Disk"} | %{

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

    + CategoryInfo          : InvalidData: (:) [Get-ScsiLun], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScsiLun

Get-Datastore : Cannot validate argument on parameter 'RelatedObject'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command

again.

At D:\Free_Info.ps1:28 char:12

+ $esxImpl | Get-Datastore | where {$_.Type -eq "VMFS"} | Get-View | %{

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

    + CategoryInfo          : InvalidData: (:) [Get-Datastore], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

Get-Cluster : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At D:\Free_Info.ps1:37 char:13

+ Get-Cluster $clusName | Get-VM | Get-View | %{

+             ~~~~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-Cluster], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster

Export-Csv : Could not find a part of the path 'D:\Temp\-LUN.csv'.

At D:\Free_Info.ps1:58 char:5

+ } | Export-Csv $csvName -NoTypeInformation -UseCulture

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

    + CategoryInfo          : OpenError: (:) [Export-Csv], DirectoryNotFoundException

    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand

Invoke-Item : Cannot find path 'D:\Temp\-LUN.csv' because it does not exist.

At D:\Free_Info.ps1:59 char:1

+ Invoke-Item $csvName

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

    + CategoryInfo          : ObjectNotFound: (D:\Temp\-LUN.csv:String) [Invoke-Item], ItemNotFoundException

    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.InvokeItemCommand

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You have to provide a ClusterName when you call the script.

Have a look at the Usage examples in the blogpost.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

As per your suggestion, here is the error

PS D:\> .\Free_Info.ps1 DEN-Compute

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

c:\Users\madhu\AppData\Local\Temp\sxyea0bm.0.cs(1) : >>> public struct LunInfo15207{npublic string ClusterName;

c:\Users\madhu\AppData\Local\Temp\sxyea0bm.0.cs(2) : public string CanonicalName;

At D:\Free_Info.ps1:16 char:1

+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

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

    + CategoryInfo          : InvalidData: (c:\Users\adm.jm...ber declaration:CompilerError) [Add-Type], Exception

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

Add-Type : c:\Users\madhu\AppData\Local\Temp\sxyea0bm.0.cs(4) : Invalid token '}' in class, struct, or interface member declaration

c:\Users\madhu\AppData\Local\Temp\sxyea0bm.0.cs(3) : public string UsedBy;

c:\Users\madhu\AppData\Local\Temp\sxyea0bm.0.cs(4) : >>> public string SizeMB;ntpublic string172;ntpublic string172;ntpublic string172;ntpublic string172;n}

At D:\Free_Info.ps1:16 char:1

+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

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

    + CategoryInfo          : InvalidData: (c:\Users\adm.jm...ber declaration:CompilerError) [Add-Type], Exception

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

Add-Type : Cannot add type. Compilation errors occurred.

At D:\Free_Info.ps1:16 char:1

+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

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

    + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException

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

New-Object : Cannot find type [LunInfo15207]: verify that the assembly containing this type is loaded.

At D:\Free_Info.ps1:48 char:8

+ $lun = New-Object ("LunInfo" + $rndNum)

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

    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException

    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

The property 'ClusterName' cannot be found on this object. Verify that the property exists and can be set.

At D:\Free_Info.ps1:49 char:1

+ $lun.ClusterName = $clusName

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

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

    + FullyQualifiedErrorId : PropertyNotFound

The property '172' cannot be found on this object. Verify that the property exists and can be set.

At D:\Free_Info.ps1:52 char:1

+ $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 D:\Free_Info.ps1:53 char:25

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

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

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

    + FullyQualifiedErrorId : PropertyNotFound

The property 'UsedBy' cannot be found on this object. Verify that the property exists and can be set.

At D:\Free_Info.ps1:54 char:18

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

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

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

    + FullyQualifiedErrorId : PropertyNotFound

The property 'SizeMB' cannot be found on this object. Verify that the property exists and can be set.

At D:\Free_Info.ps1:55 char:18

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

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

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

    + FullyQualifiedErrorId : PropertyNotFound

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.

At D:\Free_Info.ps1:58 char:5

+ } | Export-Csv $csvName -NoTypeInformation -UseCulture

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

    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

New-Object : Cannot find type [LunInfo15207]: verify that the assembly containing this type is loaded.

At D:\Free_Info.ps1:48 char:8

+ $lun = New-Object ("LunInfo" + $rndNum)

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Yes, We have ESXi nodes have an IP address as the hostname

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Have a look in the comments of that blog post.
There is one from TTEKDAMAR dated NOVEMBER 6, 2015 at 07:07, and he presents a solution for the case where ESXi nodes have an IP address as their hostname.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Thanks a lot for your help, it took me very long time to get the correct output as per the blog post.

Could you help me how to get the LUN ID to the existing script.

I am not sure where to add the below lines to get the LUN ID, please help

$lun = Get-ScsiLun -VmHost $row.VM_Host -CanonicalName $row.HDDisplayName

$row.LUN = $lun.RuntimeName.SubString($lun.RuntimeName.LastIndexof("L")+1)

Hereby attaching the working script Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try with this


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Thanks for your quick reply.

When I execute the script, I am getting the below error

The property 'rchppisesx01-624a9370c3c9a4f49000110a5' cannot be found on this object. Verify that the property exists and can be set.

At D:\Free_Info2.ps1:90 char:3

+         $lun.$esxName = $_.Value[3]

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

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

    + FullyQualifiedErrorId : PropertyAssignmentException

The property 'rchp01-624a9370c3776b99000110d8' cannot be found on this object. Verify that the property exists and can be set.

At D:\Free_Info2.ps1:90 char:3

+         $lun.$esxName = $_.Value[3]

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

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

    + FullyQualifiedErrorId : PropertyAssignmentException

0 Kudos
LucD
Leadership
Leadership
Jump to solution

My bad, I missed one entry.

Try this one.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thanks a lot LucD, it worked as expected Smiley Happy

One last thing, How can I add the below commands to the script

connect-viserver 10.10.10.10

get-cluster = abc

and get the output name as Prod_vCenter_$date.csv

When I tried using above, I am getting error

How can I remove param and use simple scripting Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can save the file I attached earlier in a file, for example Cluster-LUN.ps1.
Then you can call the function as follows (provided the file was saved in the folder where you are currently located, otherwise provide the full path)

Connect-VIServer  -Server 10.10.10.10

.\cluster-LUN.ps1 -clus abc -csvname Prod_vCenter_$date.csv


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

You are awesome LucD, it worked as expected and now I am all set with the script Smiley Happy

Thanks a lot for your help.

0 Kudos