Tag: PowerShell

Last updated by at .

Install Hyper-V on Windows Server using PowerShell

Install Hyper-V on Windows Server using PowerShell

If you want to install Hyper-V on Windows Server you can use the following PowerShell command to install the Hyper-V role. If you want to run Hyper-V, make sure your server does include the following requirements.

  • 64-bit Processor with Second Level Address Translation (SLAT)
  • CPU support for VM Monitor Mode Extension (VT-c on Intel CPU’s)
  • Processors with Intel Virtualization Technology (Intel VT) or AMD Virtualization (AMD-V) technology
  • Hardware-enforced Data Execution Prevention (DEP) must be available and enabled. Intel: XD bit (execute disable bit) AMD: NX bit (no execute bit)
  • Minimum of 4 GB memory

If you are looking for installing Hyper-V on Windows 10, check the following blog post: Install Hyper-V on Windows 10 using PowerShell

 



Install Hyper-V on Windows 10 using PowerShell

Install Hyper-V on Windows 10 using PowerShell

On since Windows 8 you can run Hyper-V on your desktop, laptop or Windows tablet. To install or enable Hyper-V on your Windows 10 machine, you just need to have the following requirements:

  • Windows 10 Enterprise, Professional, or Education (Home does not have the Hyper-V feature included)
  • 64-bit Processor with Second Level Address Translation (SLAT)
  • CPU support for VM Monitor Mode Extension (VT-c on Intel CPU’s)
  • Minimum of 4 GB memory

The easiest way to enable Hyper-V on Windows 10 is to run the following PowerShell command as an administrator:

or you can use the following CMD DISM command:

If you are looking for installing Hyper-V on Windows Server, check the following blog post: Install Hyper-V on Windows Server using PowerShell



Azure Nested Virtualization

How to setup Nested Virtualization in Microsoft Azure

At the Microsoft Build Conference this year, Microsoft announced Nested Virtualization for Azure Virtual Machines, and last week Microsoft announced the availability of these Azure VMs, which support Nested Virtualization. Nested Virtualization basically allows you to run a Hypervisor in side a Virtual Machine running on a Hypervisor, which means you can run Hyper-V within a Hyper-V Virtual Machine or within a Azure Virtual Machine, kind a like Inception for Virtual Machines.

Azure Nested Virtualization

You can use Nested Virtualization since Windows Server 2016 or the same release of Windows 10, for more details on this, check out my blog post: Nested Virtualization in Windows Server 2016 and Windows 10

With the release of the Azure Dv3 and Ev3 VM sizes:

  • D2-64 v3 instances are the latest generation of General Purpose Instances. D2-64 v3 instances are based on the 2.3 GHz Intel XEON ® E5-2673 v4 (Broadwell) processor and can achieve 3.5GHz with Intel Turbo Boost Technology 2.0. D2-64 v3 instances offer the combination of CPU, memory, and local disk for most production workloads.
  • E2-64 v3 instances are the latest generation of Memory Optimized Instances. E2-64 v3 instances are based on the 2.3 GHz Intel XEON ® E5-2673 v4 (Broadwell) processor and can achieve 3.5GHz with Intel Turbo Boost Technology 2.0. E2-64 v3 instances are ideal for memory-intensive enterprise applications.

With the upgrade to new Intel Broadwell processors, Microsoft enabled Nested Virtualization, which will allows a couple of different scenarios, when you create a Virtual Machine running Windows Server 2016.

  • You can run Hyper-V Containers (Windows Containers with additional isolation) inside an Azure VM. With future releases we will also be able to run Linux Containers in Hyper-V Containers running on a Windows Server OS.
  • You can quickly spin up and shut down new demo and test environments, and you only pay when you use them (pas-per-use)

How to Setup Nested Virtualization in Azure

Deploy Azure VM

To setup Nested Virtualization inside an Azure Virtual Machine, you first need to create a new Virtual Machines using one of the new instance sizes like Ev3 or Dv3 and Windows Server 2016.I also recommend to install all the latest Windows Server patches to the system.

Optional: Optimize Azure VM Storage

This step is optional, but if you want to better performance and more storage for your Nested Virtual Machines to run on, this makes sense.

Azure VM Data Disks

In my case I attached 2 additional data disks to the Azure VM. Of course you can choose more or different sizes. Now you can see 2 new data disk inside your Azure Virtual Machine. Do not format them, because we gonna create a new storage spaces pool and a simple virtual disk, so we get the performance form both disks at the same time. In the past this was called disk striping.

Azure VM Storage Spaces

With that you can create a new Storage Spaces Storage Pool and a new Virtual Disk inside the VM using the storage layout “Simple” which basically configures it as striping.

Azure VM Storage Spaces PowerShell

I also formatted the disk and set the drive letter to V:, this will be the volume where I will place my nested virtual machines.

Install Hyper-V inside the Azure VM

Install Hyper-V on Windows Server using PowerShell

The next step would be to install the Hyper-V role in your Azure Virtual Machine. You can use PowerShell to do this since this is a regular Windows Server 2016.This command will install Hyper-V and restart the virtual machine.

Azure VM Hyper-V

After the installation you have Hyper-V installed and enabled inside your Azure Virtual Machine, now you need to configure the networking for the Hyper-V virtual machines. For this we will use NAT networking.

Configure Networking for the Nested Environment

Hyper-V NAT Network inside Azure VM

To allow the nested virtual machine to access the internet, we need to setup Hyper-V networking in the right why. For this we use the Hyper-V internal VM Switch and NAT networking. I described this here: Set up a Hyper-V Virtual Switch using a NAT Network

Create a new Hyper-V Virtual Switch

First create a internal Hyper-V VM Switch

Configure the NAT Gateway IP Address

The Internal Hyper-V VM Switch creates a virtual network adapter on the host (Azure Virtual Machine), this network adapter will be used for the NAT Gateway. Configure the NAT gateway IP Address using New-NetIPAddress cmdlet.

Configure the NAT rule

After that you have finally created your NAT network and you can now use that network to connect your virtual machines and use IP Address from 172.21.21.2-172.21.21.254.

Now you can use these IP Addresses to assign this to the nested virtual machines. You can also setup a DHCP server in one of the nested VMs to assign IP addresses automatically to new VMs.

Optional: Create NAT forwards inside Nested Virtual Machines

To forward specific ports from the Host to the guest VMs you can use the following commands.

This example creates a mapping between port 80 of the host to port 80 of a Virtual Machine with an IP address of 172.21.21.2.

This example creates a mapping between port 82 of the Virtual Machine host to port 80 of a Virtual Machine with an IP address of 172.21.21.3.

Optional: Configure default Virtual Machine path

Since I have created an extra volume for my nested virtual machines, I configure this as the default path for Virtual Machines and Virtual Hard Disks.

Create Nested Virtual Machines inside the Azure VM

Azure Nested Virtualization

Now you can basically start to create Virtual Machines inside the Azure VM. You can for example use an existing VHD/VHDX or create a new VM using an ISO file as you would do on a hardware Hyper-V host.

Some crazy stuff to do

There is a lot more you could do, not all of it makes sense for everyone, but it could help in some cases.

  • Running Azure Stack Development Kit – Yes Microsoft released the Azure Stack Development Kit, you could use a large enough Azure virtual machine and run it in there.
  • Configure Hyper-V Replica and replicate Hyper-V VMs to your Azure VM running Hyper-V.
  • Nested a Nested Virtual Machine in a Azure VM – You could enable nesting on a VM running inside the Azure VM so you could do a VM inside a VM inside a VM. Just follow my blog post to created a nested Virtual Machine: Nested Virtualization in Windows Server 2016 and Windows 10

In my opinion Nested Virtualization is mostly help full if you run Hyper-V Containers, but it also works great, if you want to run some Virtual Machines inside a Azure VM, for example to run a lab or test something.



Hyper-V VM battery

Hyper-V gets Virtual Battery support

Last week Microsoft announced Windows 10 Insider Preview build 16215 which added a lot of new features to Windows 10. With Windows 8 Microsoft brought Hyper-V to the Windows Client Operating System, and with the Windows 10 Insider Program we can also see some Hyper-V preview features coming to live. Previously we could see feature like Nested Virtualization and more in the Windows client builds before we seen them in the server releases. With Windows 10 Insider Preview build 16215, Hyper-V gets virtual battery support, which means you can now see your machine’s battery state in your VMs. This is especially handy if you run Virtual Machines on your notebook. My guess would be, that this could also be used on server for battery support and automatic shutdown.

To enable the feature inside the Virtual Machine you have to create a Prerelease Virtual Machine using PowerShell.

Hyper-V Prerelease Virtual Machine

You can use the following PowerShell command to create a Prerelease Virtual Machine. Please remind yourself that prerelease virtual machines are not supported in production and may fail across updates.

You can now see that the Virtual Machine now has version number 254.0, which adds some hidden new features like virtual battery support.

Prerelease Virtual Machine Hyper-V Manager

My guess is that this could be available automatically per default in all virtual machines in the final version of the Windows 10 Fall Creators Update.



PowerShell for Visual Studio Code

PowerShell for Visual Studio Code 1.0 – Your improved PowerShell ISE

Microsoft yesterday not only announced the new Azure Cloud Shell, Azure PowerShell 4.0, they also announced something I was waiting for a long time. Microsoft finally announced the version 1 of the PowerShell for Visual Studio Code with a lot for great enhancements. David Wilson describes this on the PowerShell Team blog.

This supports the PowerShell development on the following platforms:

  • Windows 7 through 10 with PowerShell v3 and higher
  • Linux with PowerShell v6 (all PowerShell-supported distributions)
  • macOS and OS X with PowerShell v6

Features:

  • PowerShell ISE-like interactive development experience with the PowerShell Integrated Console
  • Rich debugging experience including variables view, call stack, watch window, and various breakpoint types
  • Integrated script analysis and code fixes provided by PSScriptAnalyzer
  • Code navigations that allow you to find definitions and references of functions across your script files
  • Highly configurable code formatter based on community best practices
  • New file and project creation using Plaster templates
  • Editor scripting API through the $psEditor object model

The biggest thing about this for me, is the support to run code line by line, which will help a lot in demos and presentations.

So what does this mean for the PowerShell ISE?

The PowerShell ISE has been the official editor for PowerShell throughout most of the history of Windows PowerShell. Now with the advent of the cross-platform PowerShell Core, we need a new official editor that’s available across all supported OS platforms and versions. Visual Studio Code is now that editor and the majority of our effort will be focused there.
However, the PowerShell ISE will remain in Windows supporting Windows PowerShell with no plans to remove it. We will consider investing effort there in the future if there is a high demand for it, but for now we think that we will be able to provide the best possible experience to the PowerShell community through Visual Studio Code.

Really looking forward to work with PowerShell for Visual Studio Code.



Azure PowerShell Module

Microsoft Azure PowerShell 4.0

Microsoft not only announced the Azure Cloud Shell, Microsoft also announced the Azure PowerShell 4.0. The new Azure PowerShell 4.0.0 adds various improvements and fixes across multiple Azure resources. Focusing on features like Container Service, Service Fabric, Container Registry, SQL, Storage, Replay and a lot more.

You can install the cmdlets via your favorite Azure PowerShell installation path indicated in the Azure PowerShell 4.0.0 release notes.



Azure Cloud Shell

Microsoft Azure Cloud Shell

Today at the Microsoft Build Conference, Microsoft announced the Azure Cloud Shell. The Azure Cloud Shell is a browser-based shell experience to manage and develop Azure resources.

Azure Cloud Shell offers a browser-accessible, pre-configured shell experience for managing Azure resources without the overhead of installing, versioning, and maintaining a machine yourself. Today it gives you a variety of different tools directly from your web browser in the Azure Portal.

Linux shell interpreter

  • Bash
  • sh

Azure tools

  • Azure CLI 2.0 and 1.0

Text editors

  • vim
  • nano
  • emacs

Source control

  • git

Build tools

  • make
  • maven
  • npm
  • pip

Containers

  • Docker
  • Kubectl
  • DC/OS CLI

Databases

  • MySQL client
  • PostgreSql client
  • sqlcmd Utility

Other

  • iPython Client

It also looks like PowerShell will be available later, hopefully it will arrive soon. Microsoft also announced Azure PowerShell 3.0.