In this short post I will show a PowerCLI script I wrote to copy ISO files from datastore y to datastore x. The datastores are in the same vCenter and virtual datacenter accessible but the vSphere hosts are located inside two different IP subnets and a firewall rule prevents to copy files between the two subnets. So I had to think about a work around. Well this one is easy. On the vCenter server I created a script to peform the following steps:
- Create two PSDrives for each Datastore
- Get al the ISO filenames
- Downlad the ISO to the c:\tmp directory from datastore y
- Upload the ISO from the C:\tmp directory to the datastore<X>\iso directory
- Remove the ISO from C:\tmp
- repeat the steps above until all the ISO files are copied to the new datastore.
The PowerCLI script to perform the described tasks:
New-PSDrive -location (get-datastore template-01) -name tpl01 -PSProvider VimDatastore -Root '\' New-PSDrive -location (get-datastore template-02) -name tpl02 -PSProvider VimDatastore -Root '\' $isos = ls tpl01:\iso\ | % {$_.Name} foreach($iso in $isos){ Write-Host "copy $($iso) to C:\tmp" -fore Yellow Copy-DatastoreItem -item tpl01:\iso\$iso -Destination C:\tmp Write-Host "copy $($iso) to template-02\iso" -fore Yellow Copy-DatastoreItem -item C:\tmp\$iso -Destination tpl02:\iso Write-Host "removing the tmp file $($iso) from C:\tmp" -fore Yellow Remove-Item C:\tmp\$iso -confirm:$false Write-Host "done" -fore Green }
So once again PowerCLI to the rescue.