We recently moved our ISO store from a legacy NFS server to our main NFS filer.
The first task was copying the actual files, which can be done via any machine that has both datastores mounted (with read-write access to the destination store).
The more significant job is reconfiguring the VMs to use the copies of the ISOs in the new datastore.
Here’s the PowerCLI script I used:
# Disconnect all CD/DVD ISOs on a particular datastore and reconnect them to the new datastore
$myvcenter = "myvcenter.host.net"
$mydatacenter = "BigDC1"
$originalISOstore = "MyFirstISOstore"
$finalISOstore = "MuchBetterISOstore"
(Get-VM -Location: (Get-Datacenter $mydatacenter)) | ForEach ( $_ )
$myDrive = Get-CDDrive $_
if ($myDrive.IsoPath -match "\["+$originalISOstore+"\]")
Set-CDDrive -CD $myDrive -IsoPath ($myDrive.IsoPath -replace $originalISOstore, $finalISOstore) -Confirm:$false
Disconnect-VIServer $myvcenter -confirm:$false
It’s fairly self-explanatory.
The biggest caveat with this is that it assumes that the source and destination stores have the same structure, but it wouldn’t be difficult to amend it to change the destination path slightly.
No Comments Yet