Automation

 View Only
Expand all | Collapse all

Noob needs help with PowerCLI (VMDK, RDM LUN listing)

  • 1.  Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 17, 2014 07:53 AM

    Hello all,

    I'm new to VMware and scripting and I would appreciate if someone could help me out with what I suppose is a fairly simple task for an experienced VMware professional. :smileyblush:


    Namely, I have here a few ESXi hosts running on vSphere 5 Enterprise licences which host VMs on local datstores as well as NetApp storage (FC LUNs). Apart from VMDKs, which sometimes reside on different datastores, some VMs also have RDM LUNs (raw devices) directly attached to them via FC.


    What I need to do is pull data from the vCenter into, say a .csv or. xls file, with regards to:

    1. All VMDKs, with the following details:

    Name of VM it's attached to, name of datastore that particular VMDK is residing on, name of NetApp controller that is hosting that datastore & path to it's FC LUN on NetApp side (storage details)

    Also if possible -- size, percentage used, logical drive name within VM

    2. All RDM LUNs, with the following details:

    Name of VM it's attached to, name of NetApp controller that is hosting that RDM LUN & path to that LUN on NetApp side (storage details)

    Also if possible -- logical drive name within VM

    I would greatly appreciate detailed instructions as I'm quite new to this game. :smileyhappy:

    Thanks for reading my message!



  • 2.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 17, 2014 10:54 AM

    Hello,

    check this.

    It can be helpful.

    Best regards,

    Pablo



  • 3.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 23, 2014 09:21 AM

    Hello Pablo,

    I saved the script as a .ps1 file and ran it,  but I get an error:

    Add-Type : Could not find file 'C:\Users\user1\AppData\Local\Temp\dkzfc16g.dll'.

    At C:\Users\user1\Desktop\Ps\yadr.ps1:21 char:9

    + Add-Type <<<<  -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

        + CategoryInfo          : NotSpecified: (:) [Add-Type], FileNotFoundException

        + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.AddTypeCommand

    New-Object : Cannot find type [DiskInfo]: make sure the assembly containing this type is loaded.

    At C:\Users\user1\Desktop\Ps\yadr.ps1:57 char:27

    +     $diskInfo = New-Object <<<<  DiskInfo

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

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

    Property 'VMname' cannot be found on this object; make sure it exists and is settable.

    At C:\Users\user1\Desktop\Ps\yadr.ps1:58 char:15

    +     $diskInfo. <<<< VMname = $vm.Name

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

        + FullyQualifiedErrorId : PropertyNotFound

    Property 'Label' cannot be found on this object; make sure it exists and is settable.

    At C:\Users\user1\Desktop\Ps\yadr.ps1:59 char:15

    +     $diskInfo. <<<< Label = $hd.DeviceInfo.Label

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

        + FullyQualifiedErrorId : PropertyNotFound

    Property 'Path' cannot be found on this object; make sure it exists and is settable.

    At C:\Users\user1\Desktop\Ps\yadr.ps1:60 char:15

    +     $diskInfo. <<<< Path = $vmdkName

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

        + FullyQualifiedErrorId : PropertyNotFound

    Property 'Thin' cannot be found on this object; make sure it exists and is settable.

    At C:\Users\user1\Desktop\Ps\yadr.ps1:61 char:15

    +     $diskInfo. <<<< Thin = $hd.Backing.ThinProvisioned

    ... and so on...

    And the thing is, every time I run the script it reports a different .dll missing. Do I need to modify the script or install something else? I've Server 2008R2 standard with it's native PowerShell 2 and vSphere PowerCLI installed.

    Thanks!



  • 4.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 23, 2014 10:36 AM

    Hello,

    I'm not a powershell specialist, anyway i would try to help you :smileyhappy:

    I guess you have two options:

    • In line 21 of the script, change "CsharpVersion3" for "CSharp" and try again the script
    • Upgrade to powershell 3.0 and try again.

    Source:

    Using CSharp (C#) code in Powershell scripts - Stefan Goßner - Site Home - TechNet Blogs

    Best regards,

    Pablo



  • 5.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 23, 2014 01:05 PM

    Hello,

    I've installed PowerShell 3.0 but now I get a different type of error:

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(10) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(9) :   public string AllocatedMB;}

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(10) : >>>     public string Snap1MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(11) :     public string Snap1Name;

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(11) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(10) :     public string Snap1MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(11) : >>>     public string Snap1Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(12) :     public string Snap2MB;

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(12) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(11) :     public string Snap1Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(12) : >>>     public string Snap2MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(13) :     public string Snap2Name;

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(13) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(12) :     public string Snap2MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(13) : >>>     public string Snap2Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(14) :     public string Snap3MB;

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(14) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(13) :     public string Snap2Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(14) : >>>     public string Snap3MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(15) :     public string Snap3Name;

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(15) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(14) :     public string Snap3MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(15) : >>>     public string Snap3Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(16) :     public string Snap4MB;

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(16) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(15) :     public string Snap3Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(16) : >>>     public string Snap4MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(17) :     public string Snap4Name;

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(17) : Expected class, delegate, enum, interface, or struct

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(16) :     public string Snap4MB;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(17) : >>>     public string Snap4Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(18) : }

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...face, or struct:CompilerError) [Add-Type], Exception

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

    Add-Type : c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(18) : Type or namespace definition, or end-of-file expected

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(17) :     public string Snap4Name;

    c:\Users\stojnov.i\AppData\Local\Temp\yykao10q.0.cs(18) : >>> }

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

        + CategoryInfo          : InvalidData: (c:\Users\stojno...f-file expected:CompilerError) [Add-Type], Exception

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

    Add-Type : Cannot add type. There were compilation errors.

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:21 char:1

    + Add-Type -Language CsharpVersion3 -TypeDefinition $DiskInfoDef

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

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

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

    New-Object : Cannot find type [DiskInfo]: make sure the assembly containing this type is loaded.

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:57 char:17

    +     $diskInfo = New-Object DiskInfo

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

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

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

    Property 'VMname' cannot be found on this object; make sure it exists and is settable.

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:58 char:5

    +     $diskInfo.VMname = $vm.Name

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

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

        + FullyQualifiedErrorId : PropertyNotFound

    Property 'Label' cannot be found on this object; make sure it exists and is settable.

    At C:\Users\stojnov.i\Desktop\Ps\yadr.ps1:59 char:5

    +     $diskInfo.Label = $hd.DeviceInfo.Label

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

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

        + FullyQualifiedErrorId : PropertyNotFound

    ... and so on...



  • 6.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 24, 2014 10:06 AM

    Hello all,

    It seems storage device information (for LUNs) aren't visible in vSphere at all, therefore matching datastores and RDM LUNs to their corresponding data containers on storage side is something that needs to be done through software that integrates with vSphere - such as NetApp OnCommand Balance or Virtual Storage Console. So, you can scratch my request on that topic.

    However, it would be good if the scripts you kindly offered for listing VMDKs could be altered to show datastore name that each VMDK is residing on.

    Cheers!



  • 7.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 17, 2014 11:00 AM

    Thanks for the link Pablo :smileyhappy:

    There is also LUN report – datastore, RDM and node visibility, which would return some of the requested info



  • 8.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 17, 2014 11:14 AM

    You welcome LucD :smileywink:

    I thought about the link you commented, but i decided to pass another one of you.

    Best regards,

    Pablo



  • 9.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 23, 2014 09:51 AM

    Hello LucD,

    This is a really neat script! However, I'm not competent enough to modify it to get the information I need. :smileyplain:

    Namely, I need the VMDK report to look something like this: VMname, Disk Label, VMDK path, capacity/allocated, datastore name, full storage path for that datastore's underlying LUN. The storage system holding the LUNs is NetApp. Your yadr script is actually close to the mark! Some of this is already incorporated in it, just needs the datastore and storage info to be added.

    And something simpler for RDM report: VMname, Disk Label, capacity, full storage path for that RDM LUN (also NetApp storage)

    To be honest LucD, I'm not sure how demanding this task/request is. But I think this would be a really insightful script for anyone doing a survey of a complex vSphere environment and lots of people would be grateful to have a tool like this at hand. Is this something you could take a bash at?

    Cheers!



  • 10.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 17, 2014 08:31 PM

    Pablo and LucD posted some great material but I have a script that may be useful as a platform to start from and may be a bit more straight forward if you are new to PowerCLI. Since there are no comments, let me know if you need me to expound on how this script works or how to expand the functionality.

    add-pssnapin VMware.VimAutomation.Core

    $report = @()

    $vcenters = @("exampleVcenter1", "exampleVcenter2")

    $vcenters | %{$vcenter = $_ ; Connect-VIServer $_ ;

    Get-view -Server $vcenter -ViewType virtualmachine | Get-VIObjectByVIView | %{

        get-harddisk -vm $_ | %{

                $row = "" | select Vcenter, VMName, HDName, HDType, HDsizeGB, WWN

                $row.Vcenter = $vcenter

                $row.VMName = $_.parent

                $row.HDName = $_.name

                $row.HDType = $_.disktype

                $row.HDSizeGB = [int]("{0:N0}" -f ($_.capacitykb/1mb))

                If(($_.disktype -eq "RawVirtual") -or ($_.disktype -eq "RawPhysical")){

                    $row.WWN = $_.ScsiCanonicalName.trimstart("naa.")

            }

                $report += $row

        }

    }

    }

    $report | export-csv -Path Alldisks.csv



  • 11.  RE: Noob needs help with PowerCLI (VMDK, RDM LUN listing)

    Posted Apr 23, 2014 10:01 AM

    Hello rsoc,

    I just tried the script and it works without a hitch.

    Could you possibly add for Flat disks: datastore name + full storage path for that datastore's underlying LUN?

    And for RawPhysical disks: full storage path for that RDM LUN?

    Thanks!