$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 } }