Hi guys.
for legal reason, I need to make snapshot (with memory) for a considerable number of vms and take them to another datastore.
So if I did it manually it would be:
take snapshot
browse datastore
copy vmdk and vmsn to another datastore
I need to automate this.
the snapshots are already done
- created text file with vm names
- Get-Content .\TEXTFILE.txt | ForEach-Object {get-vm $_ | New-Snapshot -name SNAPNAME -memory:$true }
Now, I'm trying to copy files and with the following, it does not copy everything I need... (powercli gives copy-item : Operation is not valid due to the current state of the object.) and only copies one item)
- Create csv file with: vmname,ds,folder
- use those lines:
import-csv CSVFILE.csv |
ForEach {
$ds = get-datastore -name $_.ds
$folder = $_.folder
$vmname = $_.vmname
$newds = Get-Datastore -Name DATASTORENAME
New-PSDrive -Location $newds -Name newds -PSProvider VimDatastore -Root "\"
New-PSDrive -Location $ds -Name oldds -PSProvider VimDatastore -Root "\"
copy-item "oldds:\$folder\*" "newds:\vmfolder\$vmname"
get-psdrive oldds | remove-psdrive
get-psdrive newds | remove-psdrive
}
I'm cutting my hairs overs this one.
Any ideas?
Thanks
Well, I rebooted my session and eveything works fine...
Powershell needed a rest I think 🙂
Well, I rebooted my session and eveything works fine...
Powershell needed a rest I think 🙂