Automation

 View Only
  • 1.  Anyone know a way to move a vds to a network folder?

    Posted Jul 31, 2015 03:02 PM

    I have checked all cmdlets.  I am running powercli 6.0r1 with vcenter 5.0.  There is move-inventory cmdlet,  however it only accepts items of type folder, resourcepool, datacenter, vm, vmhost, template, or cluster objects.  Otherwise its a no brainer:

    move-inventory -item $vds -Destination $folder.

    Of course it does not work.  I have been scouring for a way but am at a loss.  I checked perhaps a method on the vds or the folder to no avail as well.  Dragging and dropping works fine, so there has to be a powercli way to do it right? I also checked all the reconfig specs and objects with any clues if i can use one of them.  Or am i blantently missing something or unaware of a cmdlet?   I don't want to resort to dragging and dropping all 60+ VDSs i have.

    Thanks in advance.



  • 2.  RE: Anyone know a way to move a vds to a network folder?
    Best Answer

    Posted Jul 31, 2015 09:51 PM

    You can use the MoveIntoFolder_Task method found on the folder object.

    http://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.Folder.html

    If you have any port groups attached to the dvs they will also need to be moved as well. Here is a sample script that I wrote and tested with one dvs and two port groups. I am sure there is a more elegant approach but this should get the job done.

    $folder = Get-Folder -Type Network -Name folderName | Get-View

    $dvs = Get-VirtualSwitch -Name dvsName

    $dvPGs = $dvs | Get-VirtualPortGroup

    $count = $dvs.count + $dvPGs.count

    $list = New-Object VMware.Vim.ManagedObjectReference[] ($count)

    $list[0] = New-Object VMware.Vim.ManagedObjectReference

    $list[0].type = $dvs.Extensiondata.MoRef.Type

    $list[0].value = $dvs.Extensiondata.MoRef.Value

    $dvPgCount = 1

    foreach ($dvPg in $dvPgs) {

        $list[$dvPgCount] = New-Object VMware.Vim.ManagedObjectReference

        $list[$dvPgCount].type = $dvPg.Extensiondata.MoRef.Type

        $list[$dvPgCount].value = $dvPg.Extensiondata.MoRef.Value

        $dvPgCount++

    }

    $folder.MoveIntoFolder_Task($list)



  • 3.  RE: Anyone know a way to move a vds to a network folder?

    Posted Aug 03, 2015 12:38 PM

    Ah the moveintofolder_task method!  That's what i needed.  Thanks!