PowerCLI Move-Datastore Function

Moving datastores into folders via drag/drop can be painful. In some cases vCenter does not want to allow a drag from a long list. Here is a quick function to make moving via PowerCLI a little bit easier.

Function Move-Datastore {
    param (
        [VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl[]]
            $datastore = $(throw "Datastore(s) must be provided."),
        [VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl]
            $folder = $(throw "A destination folder must be provided.")
    )
 
    if ($folder.Type -ne "Datastore") {
        throw ("The specified folder is not a datastore folder.")
        exit
    }
 
    $dsList = @()
    foreach ($ds in $datastore) {
        $dsList += $ds.ID
    }
 
    $folder.ExtensionData.MoveIntoFolder($dsList)
}

Comments (2)

  1. Michael

    Thanks,
    Exactly what I need.

  2. Jg

    Hi, when i try to run the function i get this error, i am not very familiar with functions, can you assist with some pointers?
    Unable to find type [VMware.VimAutomation.ViCore.Impl.V1.DatastoreManagement.VmfsDatastoreImpl[]]: make surly containing this type is loaded.

Leave a Comment

Your email address will not be published.