I have been searching for a while for very simple script to copy all folders and their content from one datastore to another datastore.
These are not VM's so vmotion is not an option as far as I know. These are OVA files and ISO files in their own folders and misc. files of that sort. No running VM's.
Found this:
Managing the VMware datastore with PowerCLI (PowerShell) – 4sysops
But ideally I would like this to run all without using PSDrive so my workstation is not involved in moves at all.
One would think this is an easy task but the more I search for a simple script the harder the problem gets.
Any suggestions on this?
Not possible with a cmdlet I'm afraid.
But you can use the CopyDatastoreFile or the MoveDatastoreFile method.
Something like this for example
$srcDS = 'DS1'
$srcFolder = 'ISO1'
$dstDS = 'DS2'
$dstFolder = 'ISO2'
$fileMgr = Get-View FileManager
$src = "[$srcDS] $srcFolder/$isoName"
$srcDCMoRef = (Get-Datastore -Name $srcDS).DatacenterId
$dst = "[$dstDS] $dstFolder/$isoName"
$dstDCMoRef = (Get-Datastore -Name $dstDS).DatacenterId
$force = $true
$fileMgr.CopyDatastoreFile($src,$srcDCMoRef,$dst,$dstDCMoRef,$force)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would need to have the script to do that essentially one file at a time correct.
List the files and then a foreach loop? If I understand it correctly.
If you give the path to a folder, the folder, and all files in it, will be copied (or moved).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Very nice. I shall give it a shot.
LucD
Will the directory structure copy/build on the destination datastore exactly how it was on the source datastore?
Yes, did you notice otherwise?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have not noticed otherwise, @LUCD. I am preparing to move data from our old datastore that did not house VMs, only files such as ISOs and OVAs, to our new datastore for the same purpose. I was curious if I had to build the directory structure on new (destination) to match old (source). Your most recent answer says I don't need to build the hierachy on the new datastore, simply run your script.
Thanks Luc. I will keep you posted if I have any issues.