Streamlining Linux VM configuration on Hyper-V with the Set-LinuxVM PowerShell module

I mentioned the other day in this post (Linux Configuration Resource Kit for System Center administrators (Tips, Tricks and Resources)) that I wanted to talk a bit more about the Set-LinuxVM PowerShell module, a community-authored module available on the authors (Yusuf Ozturk) website. It makes the process very easy, but is not 100% foolproof, so it’s good to know a bit about how it works and how to mimimize your chances of problems.

In this post

  • What can Set-LinuxVM do?
  • Installing the Set-LinuxVM module
  • How does it work?
  • Set-LinuxVM in action

What can Set-LinuxVM do?

It has a number of features and functions, but perhaps the most important is #2 in the list below…automatic installation of the integration components for Hyper-V that provide enlightenments (including all-important control of the mouse when you’re in the Linux GUI).

1) Unattended IP, Hostname and DNS configuration for Linux VMs.
2) Automatic Linux integration components installation.
3) Support for multiple distributions: Debian, Ubuntu, Centos, Fedora, Redhat and Suse.
4) Automatically install CPanel for Redhat and Centos
5) Hyper-V support, so it you don’t have to manage with SCVMM (just use the -Manager “Hyper-V option)
6) Automatic Emulated NIC to Synthetic NIC support. (If it finds a legacy adapter, it will remove and install a synthetic adapter)
7) No need for internet connection (SSH access etc.) or additional changes on VM. (great if your VM is on an Internal virtual network)
8) Custom Answer File support so you can execute your own scripts.


Here’s a sample we’ll work with in this article 

Installing the Set-LinuxVM module

Install is pretty easy. Copy the code for the module from HERE,

Paste into Notepad or a script editor and save as SetLinuxVM.psm1 in the \modules directory


You can load the module from the PowerShell prompt using import-module setlinuxvm and you’re ready to use the Set-LinuxVM cmdlet. Use Get-help to retrieve some samples.

How does it work?

Here’s a very simplified rundown. The module actually didn’t work for me once  (more on this in a minute), prompting me to open the .psm1 file and look at the code a bit more closely. How it works is much less complicated than I imagined.

1) Connecting to the VM console

The module starts by connecting to the root\virtualization WMI class to find the VM you specified in the command line

Sending commands with your desired settings…

Then (using the MSVM_keyboard class) the script starts typing characters based on the parameters you specified in the command line. It’s literally like the PowerShell equivalent of SendKeys that we had in VBScript.

If you use the –InstallLIC parameter, the script download the integration components from Yusuf’s own site: This is something else you could change in the module to get an updated version of the components if you wanted.

The good news…how it works is simple. The bad news is, it’s easily derailed and fails, but doesn’t tell you that it failed!

How to maximize your chances of success?

The best thing to do in my experience is leave your Linux box at a command prompt. if the GUI is open (where you have no mouse control without the integration components), take the system back to a command prompt by connecting via SSH (using a tool like Putty) and type init 3 to take the runlevel back to a command line interface. I had the GUI up and an open window interfered with the typing of strings and keys via the script. I had to watch the console to catch the problem because the script didn’t see there was a problem. This reminded me instantly of the old days of blindly passing text strings to computers and devices with SendKeys in VBScript.

A look at Set-LinuxVM in action

It helps to have a closer look at the syntax. I was configuring a CentOS VM on Hyper-V (without VMM initially) so without the instructions I would have missed the –Manager “Hyper-V” option. In PowerShell ISE, PowerGUI or your favorite editor, enter

My final command looked like this.

If the script gets off to a successful start, you’ll see the following
If you connect to the console of the VM from Hyper-V Manager, you can watch the commands rolling across the screen. You’ll also see the following progress window on your Hyper-V host as the script progresses.

recycling after updating the network adapter from a legacy to synthetic


downloading the integration components


Performing all the configuration steps in the Linux Integration Components 2.1 manual to prepare for installation


Installing the integration components


Performing a reboot


MUCH easier than going step-by-step through the manual to install the integration components by hand. Give it a try next time you setup a Linux VM on Hyper-V.

Additional Resources

Here are a few additional resources related to Microsoft virtualization and private cloud you may find interesting.

One thought on “Streamlining Linux VM configuration on Hyper-V with the Set-LinuxVM PowerShell module

  1. Profile photo of HarishHarish


    when i am trying to execute the command , getting the below error. Could you please help me out

    i have installed the module on scvmm server and executing the command

    Set-LinuxVM -VM “LinuxCVM1” -Distro “Redhat” -Username “root” -Password “123456” -Hostname “localhost.localdomain” -IP “” -Subnet “” -Gateway “” -DNS1 “”

    ResultCode      ResultMessage
    ———-           ————-
    0                         You cannot call a method on a null-valued expression.

Leave a Reply