Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. "Reconnecting" to VMs...

"Reconnecting" to VMs...

Scheduled Pinned Locked Moved The Lounge
windows-admintoolsquestion
16 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dandy72
    wrote on last edited by
    #1

    Hyper-V makes it trivial to create a new VM and point to an existing .VHD/.VHDX file to boot from it. This makes it rather easy to take a hard drive full of VMs, and move them to another machine and run those VMs from there. Even if all you have is VHD/VHDX files and not the associated config files. You may be asked to re-activate (in the case of Windows) in some instances, but it beats recreating a VM entirely from scratch. It gets tedious however if you have *a lot* of VHDs and have to manually recreate VMs one-by-one and point each instance to a different file. Hyper-V has lots of PowerShell cmdlets - has anyone ever tried to create a script that would (a) enumerate .VHD files starting from a given root folder and (b) create a new VM for each VHD it finds? I'm not looking for a full solution. Just some pointers as to what cmdlets might be useful to get the process going.

    A P 2 Replies Last reply
    0
    • D dandy72

      Hyper-V makes it trivial to create a new VM and point to an existing .VHD/.VHDX file to boot from it. This makes it rather easy to take a hard drive full of VMs, and move them to another machine and run those VMs from there. Even if all you have is VHD/VHDX files and not the associated config files. You may be asked to re-activate (in the case of Windows) in some instances, but it beats recreating a VM entirely from scratch. It gets tedious however if you have *a lot* of VHDs and have to manually recreate VMs one-by-one and point each instance to a different file. Hyper-V has lots of PowerShell cmdlets - has anyone ever tried to create a script that would (a) enumerate .VHD files starting from a given root folder and (b) create a new VM for each VHD it finds? I'm not looking for a full solution. Just some pointers as to what cmdlets might be useful to get the process going.

      A Offline
      A Offline
      Andreas Mertens
      wrote on last edited by
      #2

      Not quite the same, but I did create a library of Hyper-V commands that I used for a project, allowed me to create a new VM, VHDs and virtual floppies, mount and unmount drives, and start/stop a VM. I haven't looked at in years though. I could brush off the cobwebs and bundle it up. Is this of interest?

      D 1 Reply Last reply
      0
      • A Andreas Mertens

        Not quite the same, but I did create a library of Hyper-V commands that I used for a project, allowed me to create a new VM, VHDs and virtual floppies, mount and unmount drives, and start/stop a VM. I haven't looked at in years though. I could brush off the cobwebs and bundle it up. Is this of interest?

        D Offline
        D Offline
        dandy72
        wrote on last edited by
        #3

        Sounds interesting, but overkill for the simple task I'm trying to do. And unless I'm misreading your response, PowerShell already has all the commands to do this nowadays. In the end, it turns out New-VM has all the params it needs to do a pretty decent job, so I banged together a smallish script after posting my previous question - by far the most complex part was deciding what to name the VMs being created based on the name of the subfolder a VHD/VHDX was found in. [Edit] My script recreated 159 VMs from 159 VHD/VHDX files it found in a bunch of folders on an external drive in well under 5 minutes. The script took less than 2 hours to write. If I ever re-use it a second time, its value will go up even more. Worth it.

        A F E 3 Replies Last reply
        0
        • D dandy72

          Sounds interesting, but overkill for the simple task I'm trying to do. And unless I'm misreading your response, PowerShell already has all the commands to do this nowadays. In the end, it turns out New-VM has all the params it needs to do a pretty decent job, so I banged together a smallish script after posting my previous question - by far the most complex part was deciding what to name the VMs being created based on the name of the subfolder a VHD/VHDX was found in. [Edit] My script recreated 159 VMs from 159 VHD/VHDX files it found in a bunch of folders on an external drive in well under 5 minutes. The script took less than 2 hours to write. If I ever re-use it a second time, its value will go up even more. Worth it.

          A Offline
          A Offline
          Andreas Mertens
          wrote on last edited by
          #4

          Understood. I needed a non-PowerShell solution, so tapped into the WMI actions to do this. I might still rework this as a library, post to Github. Originally I created this to create a DOS VM on the fly, so that users could continue to use a wine store POS application. It also included a way to allow the old DOS style printing to work with a Windows printer. Some interesting challenges all around.

          D 1 Reply Last reply
          0
          • D dandy72

            Sounds interesting, but overkill for the simple task I'm trying to do. And unless I'm misreading your response, PowerShell already has all the commands to do this nowadays. In the end, it turns out New-VM has all the params it needs to do a pretty decent job, so I banged together a smallish script after posting my previous question - by far the most complex part was deciding what to name the VMs being created based on the name of the subfolder a VHD/VHDX was found in. [Edit] My script recreated 159 VMs from 159 VHD/VHDX files it found in a bunch of folders on an external drive in well under 5 minutes. The script took less than 2 hours to write. If I ever re-use it a second time, its value will go up even more. Worth it.

            F Offline
            F Offline
            fgs1963
            wrote on last edited by
            #5

            When you said...

            Quote:

            however if you have a lot of VHDs

            I thought 30-ish... but 159?!?! Humour me... WTH does one do with 159 VMs?

            D P 2 Replies Last reply
            0
            • A Andreas Mertens

              Understood. I needed a non-PowerShell solution, so tapped into the WMI actions to do this. I might still rework this as a library, post to Github. Originally I created this to create a DOS VM on the fly, so that users could continue to use a wine store POS application. It also included a way to allow the old DOS style printing to work with a Windows printer. Some interesting challenges all around.

              D Offline
              D Offline
              dandy72
              wrote on last edited by
              #6

              Andreas Mertens wrote:

              Some interesting challenges all around

              I'll bet! :-)

              1 Reply Last reply
              0
              • F fgs1963

                When you said...

                Quote:

                however if you have a lot of VHDs

                I thought 30-ish... but 159?!?! Humour me... WTH does one do with 159 VMs?

                D Offline
                D Offline
                dandy72
                wrote on last edited by
                #7

                These are the Linux VMs I tinker with. How many Linux distributions do you know of? Variants of those distributions? Number of versions for each variant? It doesn't take long before it adds up. I'm not gonna claim I run many of them at the same time. And I only start deleting older versions when I start to run out of space. And unless you start collecting pictures/videos/music libraries (which belong on a NAS anyway), OS drives don't grow all that much. You can pack a lot of them on a 2TB SSD.

                F 1 Reply Last reply
                0
                • F fgs1963

                  When you said...

                  Quote:

                  however if you have a lot of VHDs

                  I thought 30-ish... but 159?!?! Humour me... WTH does one do with 159 VMs?

                  P Offline
                  P Offline
                  Paul Sanders the other one
                  wrote on last edited by
                  #8

                  fgs1963 wrote:

                  Humour me

                  No, you had it right first time :)

                  Paul Sanders. Not that the story need be long, but it will take a long while to make it short - Henry David Thoreau Some of my best work is in the undo buffer.

                  1 Reply Last reply
                  0
                  • D dandy72

                    These are the Linux VMs I tinker with. How many Linux distributions do you know of? Variants of those distributions? Number of versions for each variant? It doesn't take long before it adds up. I'm not gonna claim I run many of them at the same time. And I only start deleting older versions when I start to run out of space. And unless you start collecting pictures/videos/music libraries (which belong on a NAS anyway), OS drives don't grow all that much. You can pack a lot of them on a 2TB SSD.

                    F Offline
                    F Offline
                    fgs1963
                    wrote on last edited by
                    #9

                    dandy72 wrote:

                    These are the Linux VMs I tinker with.

                    It's a wonder you're not 'cidal'* - after tinkering with 159 Linux VMs. :doh: I play with 2 or 3, pick one. Use it for a couple years then rinse and repeat. * either 'homo' or 'sui'

                    D 1 Reply Last reply
                    0
                    • F fgs1963

                      dandy72 wrote:

                      These are the Linux VMs I tinker with.

                      It's a wonder you're not 'cidal'* - after tinkering with 159 Linux VMs. :doh: I play with 2 or 3, pick one. Use it for a couple years then rinse and repeat. * either 'homo' or 'sui'

                      D Offline
                      D Offline
                      dandy72
                      wrote on last edited by
                      #10

                      I typically don't spend all that much time with them individually - install them from newly-downloaded ISOs, make sure they can access the internet, download the latest updates, then leave them alone. *If* there's some distro I then decide I want to further tinker with, it's there and ready to go.

                      1 Reply Last reply
                      0
                      • D dandy72

                        Hyper-V makes it trivial to create a new VM and point to an existing .VHD/.VHDX file to boot from it. This makes it rather easy to take a hard drive full of VMs, and move them to another machine and run those VMs from there. Even if all you have is VHD/VHDX files and not the associated config files. You may be asked to re-activate (in the case of Windows) in some instances, but it beats recreating a VM entirely from scratch. It gets tedious however if you have *a lot* of VHDs and have to manually recreate VMs one-by-one and point each instance to a different file. Hyper-V has lots of PowerShell cmdlets - has anyone ever tried to create a script that would (a) enumerate .VHD files starting from a given root folder and (b) create a new VM for each VHD it finds? I'm not looking for a full solution. Just some pointers as to what cmdlets might be useful to get the process going.

                        P Offline
                        P Offline
                        Peter Adam
                        wrote on last edited by
                        #11

                        [Desired State Configuration](https://docs.microsoft.com/en-us/powershell/dsc/getting-started/winGettingStarted?view=dsc-1.1) may help

                        D 1 Reply Last reply
                        0
                        • D dandy72

                          Sounds interesting, but overkill for the simple task I'm trying to do. And unless I'm misreading your response, PowerShell already has all the commands to do this nowadays. In the end, it turns out New-VM has all the params it needs to do a pretty decent job, so I banged together a smallish script after posting my previous question - by far the most complex part was deciding what to name the VMs being created based on the name of the subfolder a VHD/VHDX was found in. [Edit] My script recreated 159 VMs from 159 VHD/VHDX files it found in a bunch of folders on an external drive in well under 5 minutes. The script took less than 2 hours to write. If I ever re-use it a second time, its value will go up even more. Worth it.

                          E Offline
                          E Offline
                          englebart
                          wrote on last edited by
                          #12

                          This is a good example where you should post this as a question in a forum and then provide your answer. Google will help you find it later.

                          D 1 Reply Last reply
                          0
                          • E englebart

                            This is a good example where you should post this as a question in a forum and then provide your answer. Google will help you find it later.

                            D Offline
                            D Offline
                            dandy72
                            wrote on last edited by
                            #13

                            Well, I have my script now, and it's in a location where I won't have to search for long to find it. I considered posting it as a tip, but ultimately there's more code in the script trying to decide what folder name to use to name the VM (~40 lines) than actually creating it (one line)

                            1 Reply Last reply
                            0
                            • P Peter Adam

                              [Desired State Configuration](https://docs.microsoft.com/en-us/powershell/dsc/getting-started/winGettingStarted?view=dsc-1.1) may help

                              D Offline
                              D Offline
                              dandy72
                              wrote on last edited by
                              #14

                              I'm somewhat familiar with DSC. All I was trying to do here is "enumerate all existing VHD files, create a bog-standard VM mapping to each one of them". As I understand it, DSC serves a different purpose (defining templates, creating resources configured as dictated by said templates).

                              P 1 Reply Last reply
                              0
                              • D dandy72

                                I'm somewhat familiar with DSC. All I was trying to do here is "enumerate all existing VHD files, create a bog-standard VM mapping to each one of them". As I understand it, DSC serves a different purpose (defining templates, creating resources configured as dictated by said templates).

                                P Offline
                                P Offline
                                Peter Adam
                                wrote on last edited by
                                #15

                                DSC does not take a photo of the current setup and builds it again on the target system?

                                D 1 Reply Last reply
                                0
                                • P Peter Adam

                                  DSC does not take a photo of the current setup and builds it again on the target system?

                                  D Offline
                                  D Offline
                                  dandy72
                                  wrote on last edited by
                                  #16

                                  Well, nothing really needs to be "rebuilt" in this case. I just have a bunch of fully functional VMs sitting on a disk. Their config files aren't that important; what matters is their disks (VHD files). It's really not all that different than taking an existing hard drive and putting it into another machine so it can boot from it. What I needed to do in my case is create new VMs, but at the step where you can either create a new VHD or use an existing file - point it to an existing file on disk. I really don't think DSC could have contributed much here. I could very well be wrong, but that's not my understanding of what DSC tries to do.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups