PowerCLI

 View Only
  • 1.  POWERCLI Script Resize VMFS Datastore

    Posted Sep 04, 2014 12:20 PM

    Hi,

    I have a problem when expanding datastores in 5.0.U1, U2, U3 versions. When large disk cabin, ESXi recognizes the new size, but in "Properties" Datastorage the button "Increase" this is disabled:

    I have opened a case with vmware and was told that is a workaround for versions 5.0.X and 5.1.x and  in the 5.5.x version is corrected. He sent me this link: VMware KB:    Cannot grow VMFS datastore, the Increase button is disabled  but I can not apply because it involves service stop.

    I found this KB VMware KB:    Growing or expanding a VMFS volume or datastore  and following the steps sometimes allows me to do the expansion, I enable the "Increase", but  many times the button  not working, continues disabled.

    I found thisl post "Scripted resize of VMFS datastores" but the script fails me, I can not make it work.

    The script is this:

    $ds = Get-Datastore -Name "Volume05"

    $dsscsi = get-datastore $ds | get-scsilun

    $dscanonical = $dsscsi.CanonicalName

    $esx = Get-View $ds.ExtensionData.Host[0].Key

    $storSys = Get-View $esx.ConfigManager.StorageSystem

    $dsSys = Get-View $esx.ConfigManager.DatastoreSystem

    $vmfsPath = $ds.ExtensionData.Host[0].MountInfo.Path

    $storSys.RescanAllHba()

    $extent = $dsSys.QueryVmfsDatastoreExpandOptions($ds.ExtensionData.MoRef)

    $spec = New-Object VMware.Vim.HostScsiDiskPartition

    $spec.diskName = $dscanonical

    $spec.partition = "1"

    if($extent.Count -ne 0){

      $storsys.ExpandVmfsExtent($vmfspath,$spec)

    }

    The error I get is:

    Excepción al llamar a "ExpandVmfsExtent" con los argumentos "2": "A specified parameter was not correct.

    "

    En E:\Resize_VMFS_01.ps1: 15 Carácter: 3

    +   $storsys.ExpandVmfsExtent($vmfspath,$spec)

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

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException

    Please can someone help me?

    Regards

    Daniel



  • 2.  RE: POWERCLI Script Resize VMFS Datastore

    Posted Sep 04, 2014 02:02 PM

    Did you already check the vpx logs on the vCenter ?

    There is sometimes more information about the error available in there.



  • 3.  RE: POWERCLI Script Resize VMFS Datastore

    Posted Sep 04, 2014 03:17 PM

    Hi LucD,

    I see the log, and i see this fail:

    2014-09-04T16:56:13.825+02:00 [06852 verbose 'Default'] [VpxVmomi] Invoking [expandVmfsExtent] on [vim.host.StorageSystem:storageSystem-248] session [52825573-1aaa-1f33-a1f7-153f75433f20(52e66350-8c12-35c0-a008-b3840d7b6986)]

    2014-09-04T16:56:13.825+02:00 [06852 verbose 'PropertyProvider' opID=babd66e] RecordOp ASSIGN: info.reason, task-262761

    2014-09-04T16:56:13.825+02:00 [06852 verbose 'PropertyProvider' opID=babd66e] RecordOp ASSIGN: info.eventChainId, task-262761

    2014-09-04T16:56:13.840+02:00 [06852 verbose 'PropertyProvider' opID=babd66e] RecordOp ADD: recentTask["task-262761"], host-248

    2014-09-04T16:56:13.840+02:00 [06852 verbose 'PropertyProvider' opID=babd66e] RecordOp ADD: recentTask["task-262761"], TaskManager

    2014-09-04T16:56:13.840+02:00 [09644 verbose 'PropertyProvider'] RecordOp ASSIGN: info.startTime, task-262761

    **********2014-09-04T16:56:13.840+02:00 [09644 verbose 'Default'] [VpxLroList::ThreadMainEntry] Unlocked _propProvider to call into external code

    2014-09-04T16:56:13.840+02:00 [09644 verbose 'Default'] [VpxLRO::LroMain] Invoking _currentMain

    2014-09-04T16:56:13.840+02:00 [09644 verbose 'PropertyProvider' opID=babd66e] RecordOp ASSIGN: info.state, task-262761

    2014-09-04T16:56:13.840+02:00 [09644 verbose 'PropertyProvider' opID=babd66e] RecordOp ASSIGN: info.cancelable, task-262761

    2014-09-04T16:56:13.840+02:00 [00260 verbose 'QsAdapter.HTTPService'] HTTP Response: Complete (processed 2862598 bytes)

    2014-09-04T16:56:13.856+02:00 [09644 info 'Default' opID=babd66e] [VpxLRO] -- BEGIN task-262761 -- host-248 -- vim.host.StorageSystem.expandVmfsExtent -- 52825573-1aaa-1f33-a1f7-153f75433f20(52e66350-8c12-35c0-a008-b3840d7b6986)

    2014-09-04T16:56:13.856+02:00 [04152 verbose 'QsAdapter.HTTPService'] User agent is 'VMware vim-java 1.0'

    2014-09-04T16:56:13.856+02:00 [04152 verbose 'QsAdapter.HTTPService'] HTTP Response: Complete (processed 4432 bytes)

    2014-09-04T16:56:13.871+02:00 [00260 verbose 'QsAdapter.HTTPService'] User agent is 'VMware vim-java 1.0'

    2014-09-04T16:56:13.871+02:00 [00260 verbose 'QsAdapter.HTTPService'] HTTP Response: Complete (processed 4432 bytes)

    2014-09-04T16:56:13.871+02:00 [09644 error 'Default' opID=babd66e] (Log recursion level 2) vmodl.fault.InvalidArgument

    ------ In-memory logs end   --------

    2014-09-04T16:56:13.871+02:00 [09644 error 'Default' opID=babd66e] Section for VMware VirtualCenter, pid=16992, version=5.0.0, build=build-455964, option=Release

    -->

    2014-09-04T16:56:13.871+02:00 [09644 info 'Default' opID=babd66e] [VpxLRO] -- FINISH task-262761 -- host-248 -- vim.host.StorageSystem.expandVmfsExtent -- 52825573-1aaa-1f33-a1f7-153f75433f20(52e66350-8c12-35c0-a008-b3840d7b6986)

    2014-09-04T16:56:13.871+02:00 [09644 info 'Default' opID=babd66e] [VpxLRO] -- ERROR task-262761 -- host-248 -- vim.host.StorageSystem.expandVmfsExtent: vmodl.fault.InvalidArgument:

    --> Result:

    --> (vmodl.fault.InvalidArgument) {

    -->    dynamicType = <unset>,

    -->    faultCause = (vmodl.MethodFault) null,

    -->    invalidProperty = <unset>,

    -->    msg = "A specified parameter was not correct.

    --> ",

    --> }

    --> Args:

    -->

    --> Arg vmfsPath:

    --> "/vmfs/volumes/540726c1-b26f3c27-2e13-e41f13908ee6"

    --> Arg extent:

    --> (vim.host.ScsiDisk.Partition) {

    -->    dynamicType = <unset>,

    -->    diskName = "naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672 naa.60a98000417636726d2b4544706c4672",

    -->    partition = 1,

    --> }



  • 4.  RE: POWERCLI Script Resize VMFS Datastore

    Posted Sep 04, 2014 04:14 PM

    The issue seems to be the diskName property, that should hold only 1 canonicalname.

    Try changing

    $dscanonical = $dsscsi.CanonicalName

    into

    $dscanonical = $dsscsi.CanonicalName | Select -First 1



  • 5.  RE: POWERCLI Script Resize VMFS Datastore

    Posted Sep 04, 2014 08:06 PM

    Hi LucD,

    The error now is this:

    No se puede convertir el argumento "datastore", con el valor: "System.Object[]", para "QueryVmfsDatastoreExpandOptions", al tipo

    "VMware.Vim.ManagedObjectReference": "No se puede convertir el valor "System.Object[]" de tipo "System.Object[]" al tipo

    "VMware.Vim.ManagedObjectReference"."

    En E:\1D\UTILIDADES_MIAS\Scripts_PowerShell_PowerGUI\ESX\Resize_VMFS_01.ps1: 10 Carácter: 1

    + $extent = $dsSys.QueryVmfsDatastoreExpandOptions($ds.ExtensionData.MoRef)

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

        + CategoryInfo          : NotSpecified: (:) [], MethodException

        + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

    Excepción al llamar a "ExpandVmfsExtent" con los argumentos "2": "An error occurred during host configuration."

    En E:\1D\UTILIDADES_MIAS\Scripts_PowerShell_PowerGUI\ESX\Resize_VMFS_01.ps1: 15 Carácter: 3

    +   $storsys.ExpandVmfsExtent($vmfspath,$spec)

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

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException



  • 6.  RE: POWERCLI Script Resize VMFS Datastore

    Posted Sep 04, 2014 09:16 PM

    It looks as if more than 1 object is returned for the Get-Datastore.

    Try like this perhaps

    $ds = Get-Datastore -Name "Volume05" | Select -First 1

    $dsscsi = Get-ScsiLun -Datastore $ds | Select -First 1 

    $dscanonical = $dsscsi.CanonicalName 

    $esx = Get-View $ds.ExtensionData.Host[0].Key  

    $storSys = Get-View $esx.ConfigManager.StorageSystem  

    $dsSys = Get-View $esx.ConfigManager.DatastoreSystem 

    $vmfsPath = $ds.ExtensionData.Host[0].MountInfo.Path 

    $storSys.RescanAllHba() 

    $extent = $dsSys.QueryVmfsDatastoreExpandOptions($ds.ExtensionData.MoRef) 

    $spec = New-Object VMware.Vim.HostScsiDiskPartition 

    $spec.diskName = $dscanonical 

    $spec.partition = "1" 

    if($extent.Count -ne 0){ 

       $storsys.ExpandVmfsExtent($vmfspath,$spec

    }  



  • 7.  RE: POWERCLI Script Resize VMFS Datastore

    Posted Sep 05, 2014 08:49 AM

    Hi LucD,

    I tested the script, is giving error, gives another error:

    =========================================================================================================

    In the powegui i see this error:

    Excepción al llamar a "ExpandVmfsExtent" con los argumentos "2": "An error occurred during host configuration."

    En C:\Users\x091683\AppData\Local\Temp\d5636c20-5e9c-4106-9bac-471ed0fbaf65.ps1: 14 Carácter: 4

    +    $storsys.ExpandVmfsExtent($vmfspath,$spec)

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

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : VimException

    =========================================================================================================

    And in the VC i see this error:

    Operation failed, diagnostics report: Unable to grow Filesystem, please see VMkernel log fordetails : Underlying device has no free space.

    =========================================================================================================

    In "error report" show this error:

    Event Details:

    Type: info

    Time: 05/09/2014 9:47:14

    Task Details:

    Name: ExpandVmfsExtent

    Description: Expand VMFS extent

    Error Stack:

    Operation failed, diagnostics report: Unable to grow Filesystem, please see VMkernel log fordetails : Underlying device has no free space

    Additional Event Details:

      Type ID: Info

    Target Object Type: ClusterComputeResource

    DataCenter Object Type: Datacenter

    Host Object Type: HostSystem

    Host Build: 1117897

    ChainId: 12240846

    Additional Task Details:

      VC Build: 455964

    Task Id: Task

    Cancelable: False

    Cancelled: False

    Description Id: host.StorageSystem.expandVmfsExtent

    Event Chain Id: 12240846

    =========================================================================================================

    In the ESX, in the vmkernel.log show this error:

    2014-09-05T08:32:01.800Z cpu17:33352330)VmkAccess: 207: ipAddr = 0.0.0.0, port = 68

    2014-09-05T08:32:04.210Z cpu9:126562)LVM: 7972: No unused capacity on device naa.60a98000417636726d2b4544706c4672:1

    2014-09-05T08:32:04.210Z cpu9:126562)LVM: 7887: Error adding space (0) on device naa.60a98000417636726d2b4544706c4672:1 to volume 540726c1-6294532b-5943-e41f13908ee6: Underlying device has no free space

    =========================================================================================================

    But this is not right. Is free space on the disk.



  • 8.  RE: POWERCLI Script Resize VMFS Datastore

    Posted Dec 17, 2015 12:04 AM

    Just got this working in 5.5. I think the issue is that you're using the wrong function for your intended purpose (should perhaps be using ExpandVmfsDatastore instead of ExpandVmfsExtent).

    # The start of a datastore name. E.g., if you have multiple datastores:

    # ds1, ds2, ds3

    # and want to expand all of them, put 'ds' here.

    $dsPrefix = 'dsprefix'

    connect-viserver vcenter

    Write-Host

    $rds = get-datastore | ? { $_.Name -match "^$($dsPrefix).*$" } | sort-object

    if ($rds.Count -ge 0) {

        $vmhost = get-vmhost -id $rds[0].ExtensionData.Host[0].Key

        $vmhostView = get-view $vmhost

        $dsSys = get-view $vmhostView.ConfigManager.DatastoreSystem

        $rds | % {

            $ds = $_

            $expandOpts = $dsSys.QueryVmfsDatastoreExpandOptions($ds.ExtensionData.MoRef)

            if (($expandOpts.Count -gt 0) -and ($expandOpts[0].Spec.GetType().Name -eq "VmfsDatastoreExpandSpec")) {

                $userResponse = Read-Host -Prompt "Expand VMFS datastore '$($ds.Name)' [Y/N] (default 'Y')?"

                if ((-not $userResponse) -or ($userResponse -eq '') -or ($userResponse -ieq 'y')) {

                    Write-Host "Expanding VMFS datastore '$($ds.Name)'"

                    $dsSys.ExpandVmfsDatastore($ds.Id, $expandOpts[0].Spec)

                }

            }

        }

    }

    else {

        Write-Host "No datastores found."

    }

    disconnect-viserver -confirm:$false -force