Hi,
I put together using google a little script for creating a VM. The script works fine! My issue is that i want it to run on multiple servers and not all of them have the same drive letter. Some of them use the D: while others the E:
The good thing is that the script is running from the same drive letter. How could i change it in order to represent the current letter?
I was thinking that if i know the exact subfolder of the script (which i do) then i could change the "D:\VM\$vm_name" to "..\..\VM\$vm_name"
any ideas would be appreciated!
Thanks.
CLS
$vm_name= Read-Host "Enter new VM name"
#get path to xml file
$vmconfig = get-item "D:\Templates\template\Virtual Machines\*.xml" | select -ExpandProperty Fullname
$vm_path= "D:\VM\$vm_name"
New-Item -ItemType directory -Path $vm_path
Import-VM -Path $vmconfig -copy -GenerateNewId -SmartPagingFilePath $vm_path -SnapshotFilePath $vm_path -VhdDestinationPath $vm_path
Get-VM "Template" | Rename-VM -NewName $vm_name -PassThru
$vhd = Get-VMHardDiskDrive -VMName $vm_name
$oldName = $vhd.Path
$newName = ($vm_path + "\" + $vm_name + "_C.vhdx")
Rename-Item $oldName $newName
Set-VMHardDiskDrive –VMName $vm_name –Path $newName