| Powershell create Scheduled Tasks » |
When you have a Windows 2008 R2 machine and the HyperV role enabled but no SCVVM or whatever. Cloning is not possible out-of-the-box but you can create an export.
As soon as you want to import this export again you will get a message about the machine already exists. When you rename the vhd and replace all the references in the config files of the export you ARE able to import the machine again.
That's why I created a .ps1 script to list all the exports in the current folder and rename the choosen one.
Follow up:
$a = Get-ChildItem . -Exclude *.*
$i = -1
foreach ($aitem in $a) {
$i++
Write-Host $i"." $aitem.name
}
$image = Read-Host "Please select the Image by typing the number in front of the os"
do {$answer = Read-Host "The selected image is '"$a[$image].name"' Is this correct? [Y/N]" } Until ($answer -eq "Y" -or $answer -eq "y" -or $answer -eq "N" -or $answer -eq "n")
If ($answer -eq "Y")
{
Write-Host "This is the selected image" $a[$image].name
$newimage = Read-Host "Please type new machine name"
do {$answer = Read-Host "The HyperV systemname will be '$newimage'. Is this correct? [Y/N]" } Until ($answer -eq "Y" -or $answer -eq "y" -or $answer -eq "N" -or $answer -eq "n")
If ($answer -eq "Y" -or $answer -eq "y")
{
Write-Host "This will be the name of the new system '$newimage'"
$b = Get-ChildItem $a[$image] -Recurse -Include *.vhd
$oldname = $b.BaseName
$c = Get-ChildItem $a[$image] -Recurse -Exclude *.vhd -Include *.*
foreach ($citem in $c) {
Write-Host $citem.name
$content = Get-Content -Encoding Unicode $citem
$content -replace $oldname, $newimage | Set-Content -Encoding Unicode $citem | Out-Null
}
$newimagename = $newimage + ".vhd"
Get-ChildItem $a[$image] -Recurse -Include *.vhd | Rename-Item -NewName $newimagename
}
}
Attachments:
renamevm.ps1 (1.3 KB)
5 comments
-
§ free pinball said on : 07/17/10 @ 23:55
I love this place - I've bookmarked it and will come back
-
§ Roofing King of Prussia Pa said on : 07/26/10 @ 02:18
I was just doing some surfing on my Samsung Phone during my break at work , and I came across something I thought was interesting . It linked to your site so I hopped over. I can't really figure out the relevance between your site and the one I came from, but your site good none the less .
-
§ scholarships for hispanics said on : 08/12/10 @ 12:56
nice post,its helpful to me.
-
§ BPO Consultant said on : 09/04/10 @ 00:23
Nice site, you know after 4 years of studies I guess I have to admit I was wrong about this. Thanks for opening my eyes!
-
§ Autos
said on : 09/05/10 @ 12:00
Sometimes I just wonder...