This article provides a method to copy files to and from a Windows workstation or server to a vCenter Server datastore (VMFS or NFS) using VMware vSphere PowerCLI. For more information on PowerCLI, including installation and usage, see the vSphere PowerCLI documentation.
Note: Automation or scheduling of this method is outside the scope of this article. For information on automation and scheduling, see the Microsoft Windows Task Scheduler documentation.
The PowerCLI Datastore Provider (VimDatastore
) works with the PowerShell drive functionality to expose access to files and directories on vSphere datastores. You can use the default vmstore:
or vmstores:
inventory drives, or create custom drives with the New-PSDrive
commandlet. Files and directories can be copied using the Copy-DatastoreItem
commandlet. For more information, see the The Datastore Provider section of the vSphere PowerCLI Administration Guide.
Connect-VIServer -Server ServerNameOrIPAddress
$datastore = Get-Datastore "MyDatastoreName"
ds:
, that maps to $datastore
:New-PSDrive -Location $datastore -Name ds -PSProvider VimDatastore -Root "\"
Connect-VIServer -Server ServerNameOrIPAddress
Set-Location
command:Set-Location PowerShellDriveName:\
Set-Location ds:\
Set-Location vmstore:\
Get-ChildItem
command:ds:\> Get-ChildItem
LastWriteTime Type Length Name
------------- ---- ------ ----
8/31/2010 12:51 PM Folder virtualmachine1
6/14/2011 11:34 AM Folder virtualmachine1
6/8/2011 8:13 PM Folder virtualmachine1
Set-Location
command.Set-Location "<DirectoryName>"
Set-Location "virtualmachine1"
Connect-VIServer -Server ServerNameOrIPAddress
Copy-DatastoreItem
command:Copy-DatastoreItem -Item SourceDatastoreItem(s) [-Destination DestinationLocation] [-Force] [-Recurse] [-Confirm]
Copy-DatastoreItem -Item ds:\virtualmachine1\virtualmachine1.vmx -Destination c:\virtualmachine1\
Copy-DatastoreItem -Item c:\virtualmachine2\* -Destination ds:\virtualmachine2\
Copy-DatastoreItem
. Copy the files to the PowerCLI host's local filesystem temporarily, and then copy to the destination.This method is not the only way to copy files to and from vSphere datastores. For other options, see the Product Documentation for your version of vSphere and the vSphere Command-Line Interface documentation.
Copia de archivos hasta y desde los volúmenes del almacén de datos vSphere mediante PowerCLI