Jun 25

I had the need to automate moving about 50 ISO files from one datastore to another during a storage array migration a short while ago, so I wanted to share this script with you all in case you ever find the need for this or similar.

It’s rather simple, and you just need to edit this with the names of your datastores and folder structure (top folder only):

#Set's Old Datastore
$oldds = get-datastore "Old Datastore Name"

#Set's New Datastore
$newds = get-datastore "New Datastore Name"

#Set's ISO Folder Location
$ISOloc = "Subfolder_Name\"

#Map Drives
new-psdrive -Location $oldds -Name olddrive -PSProvider VimDatastore -Root "\"
new-psdrive -Location $newds -Name newdrive -PSProvider VimDatastore -Root "\"
#Copies Files from Old to New
copy-datastoreitem -recurse -item olddrive:\$ISOloc* newdrive:\$ISOloc

Line 1: Change the script to have the name of the datastore you are moving the files FROM.
Line 5: Change the script to have the name of the datastore you are moving the files TO.
Line 8: Change the script to have the name of your ISO subdirectory. Do not remove the “\” unless you have no subfolder.
Lines 11 & 12: Maps PowerShell drives to those datastores.
Line 14: Copies the files.

Tags: , , , , , , , , ,

Categories: PowerCLI ,VMware

8 Responses to “Copy Files Between Datastores – PowerCLI”

  1. caruso says:

    Thanks bro.

    Worked like a charme and saved me.

  2. Dunedin IT says:


    Your simple bit of code got me on the right path to automating copy over from the GhettoVCB backup.


  3. Nick says:

    thanks very much it worked very well for me too

  4. Pete Walker says:

    Very helpful. This was driving me berserk, and I’m so glad I found this post. Thank you so much.

  5. Chris says:

    Nice one mate. Very useful!

  6. […] to the new datastores.  So I did some Internet searches and found the following blog post:  Copy Files Between Datastores – PowerCLI.   Dan Hayward posted a useful PowerCLI script that he used to copy ISO files from one datastore […]

Leave a Reply

%d bloggers like this: