Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 210400

Re: Script to Remove HDDs other than HDD1 from VM and re-add it back.

$
0
0

Hi Friends,

 

Can you please review the script below, Script is to shutdown the VM remove the disk other than HDD1 and then re-add it back.

 

My script works till remove HDD but getting error while adding it back.. i am not sure how to give path of the disk.

 

$vmname = "testvm02"

Get-VM -Name $vmname | %{

 

 

  Write-Host "Stoping VM" $vmname

  $vmname | Get-VMGuest | where {$_.State -eq "Running"} | Shutdown-VMGuest -Confirm:$false

  $HDDfile = Get-HardDisk -VM $vmname | Where-Object {$_.Name -ne 'Hard Disk 1'} | select Filename

   Get-HardDisk -VM $vmname | Where-Object {$_.Name -ne 'Hard Disk 1'} | Remove-Harddisk -Confirm:$false

   New-HardDisk -VM $vmname -DiskPath {"$HDDfile.Filename"}

 

   Write-Host "Starting VM" $vmname

   $vmname | Start-Vm -Confirm:$false

 

}


Viewing all articles
Browse latest Browse all 210400

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>