PowerTip: Use PowerShell to Add Disks to a Live Virtual Machine

PowerTip: Use PowerShell to Add Disks to a Live Virtual Machine

  • Comments 9
  • Likes

Summary: Use Windows PowerShell to add disks to a live virtual machine on Hyper-V.

Hey, Scripting Guy! Question How can I easily add disk drives to my virtual machine while it is live?

Hey, Scripting Guy! Answer Use the Add-VMScsiController and Add-VMHardDiskDrive cmdlets.

First, stop the virtual machine, add the SCSI controller, then start the virtual machine:

STOP-VM "My Virtual Machine"

ADD-VMScsiController -VMname "My Virtual Machine"

START-VM "My Virtual Machine"

Now attach disks live:

NEW-VHD -Dynamic C:\VHD\MyDrive.vhdx -SizeBytes 60GB

ADD-VMHardDiskDrive -vmname "My Virtual Machine" -path C:\VHD\MyDrive.VHDX -ControllerType SCSI

 

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • "Use PowerShell to Add Disks to a Live Virtual Machine"

    ...

    "First, stop the virtual machine"

    Guys...How is this 'Live'?

  • I agree, the title is more than a little misleading.

  • @Paul_W

    @Peter_Zerger

    i wouldn't call it misleading but instead a misinterpretation. If your VM already has a SCSI controller attached to it then the title 'Use PowerShell to Add Disks to a Live Virtual Machine' is truthful but if you don't the way you go about being able to add drives to live VMs is explained

  • @Paul_W

    'Live' has many different interpretations.  It can be dependent on 'planet', on how much coffee you have had and by religion.  To animists 'live' includes rocks and blocks and on the things that don't go bump in the night.

    Have you looked under you bed lately?    

    It's just the beast under your bed

    In your closet in your head

    haa!  haa! ha! ha! ha!

  • @jrv

    Hi JRV,

    Look up Hyper-V's 'live migration' to see what MS defines as 'live'.

    (It means a running VM...)

    p.s. Cut down on the weed man

  • @Paul_W

    Hey - it's Friday and I just finished the deployment from Hell.

    No weeds - I have my lawn done by a really excellent landscaper.

  • hehe... I sympathize.

    I hope it all went well, or you'll know on monday I guess ;-)

  • @ALL Sorry for the confusion caused by the title ... often brevity is the causality of clarity -- or is it vice versa. Anyway thanks for helping to me to keep it real.

  • @Ed

    I understood that 'live' was a transient state even if no once else could see that.

    What do they say?  "Live is what you make of it."

    "