The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • about.me

    about.me/mikaelnystrom

  • Archives

  • Meta

Archive for the ‘Hyper-V’ Category

PowerShell is King – Simple function to test a VMSwitch is present

Posted by Mikael Nystrom on May 27, 2016

When building VM’s, they are usually connected to a Hyper-V switch, so when working for a customer I suddenly needed to verify that the switch actually exists before building the VM. One way to solve this is of course to use Get-VMSwitch –Name, but if it cant find it, it blows up and turns red and angry, the other way is to use “Count”, that way I can return whatever I need, in this case I Return True or False.

Usage:

Create a .psm1 file, copy the content, paste into the file, save the file and use the Import-Module function. After that you can test it by running commands similar to this.

image
Using the function to test a VMswitch is present on the local machine.

The Function:

Function Test-FAVMSwitchexistence
{
    Param(
        [string]$VMSwitchname
    )
        $Item = (Get-VMSwitch | Where-Object -Property Name -EQ -Value $VMSwitchname).count
        If($Item -eq '1'){Return $true}else{Return $false}
}

Mike

Posted in Hyper-V, PowerShell | Tagged: , | Leave a Comment »

Windows Server 2016 – Create a NAT network using the Hyper-V switch

Posted by Mikael Nystrom on March 3, 2016

In Windows Server 2016 (TP4) and Windows 10 1511 it is possible to create a Hyper-V Switch with NAT functionality, including publishing rules. The purpose is to run containers, but it can of course be used to run normal virtual machines. This means that you can very easy build an infrastructure environment with access to Internet and reverse without having a virtual router or firewall, pretty neat IMHO. Currently, the only way to create the switch is using PowerShell, but hey, I don’t mind…

Create the Switch

The following command will create a VM Switch for NAT usage with a subnet of 192.168.1.0/24. The net result will be a switch and an Internal network adapter with the IP address 192.168.1.1

New-VMSwitch -Name ViaMonstraNAT -SwitchType NAT -NATSubnetAddress 192.168.1.0/24

Create the NAT rule to get out

The following command will create a NAT rule for all machines connected to the Switch that uses the default gateway to get out.

New-NetNat -Name ViaMonstraNAT -InternalIPInterfaceAddressPrefix 192.168.1.0/24

Create a publishing rule

The following rule will open the “firewall” and redirect traffic on the hyper-v host port tcp/80 to the machine on the VM Switch with the IP address 192.168.1.200 to tcp/80

Add-NetNatStaticMapping -NatName ViaMonstraNAT -Protocol TCP -ExternalPort 80 -InternalIPAddress 192.168.1.200 -InternalPort 80 -ExternalIPAddress 0.0.0.0

Check if it works

You can use the following PowerShell commandlets to see the configuration after it has been done.

image
Get-VMSwitch will show you the switch with SwitchType NAT.

image
Get-NetNat will show you the NAT configuration bound to the switch.

image
Get-NetNatStaticMapping will show you the publishing rule.

image
Get-NetNatSession will show you current NAT sessions.

/Mike

Posted in Hyper-V, Windows 10, Windows Server 2016 | Tagged: , , | 3 Comments »

Working in the Datacenter–Enable Virtual TPM in Hyper-V gives you the ability to test bitlocker in a VM

Posted by Mikael Nystrom on January 26, 2016

Last night a friend contaced me and said “-Did you ever post the vTPM thing?”, i did say yes, but i was wrong, so here it is…

Simple, without testing and verfication, a deployment solution will fail. One of the tasks that takes a lot of time to test and verify is BitLocker and that also includes TPM. Windows 10 and Windows Server 2016 gives you the ability to create Virtuial Machines with a Virtual TPM Chip 2.0.

image
A VM running Windows Server 2012 R2 with a vTPM chip, The VM is running on Windows Server 2016.

The How-To Part

You need to run Windows Server 2016 TP4 or Windows 10.

On the host, add Isolated UserMode, Hyper-V and Hostguardian Services, by running the following powershell command(elevated):

Add-WindowsFeature -Name “Isolated-UserMode”,”Hyper-V”,”HostGuardian” -IncludeAllSubFeature –IncludeManagementTools

If needed, restart the host.

Before you can enable the vTPM you need to have a Guardian Service guardian object and with that you can crerate a Key Protector.

New-HgsGuardian -Name ‘Guardian’ -GenerateCertificates
$Owner = Get-HgsGuardian -Name ‘Guardian’
$KeyProtector = New-HgsKeyProtector -Guardian $Owner -Owner $Owner –AllowUntrustedRoot

Great, the last piece is to enable the vTPM

Set-VMKeyProtector -VMName ‘WSUS01’ -KeyProtector $KeyProtector.RawData
Enable-VMTPM -VMName ‘WSUS01’

/Mike

Posted in Deployment, Hyper-V, OSD, Windows 10, Windows Server 2016, Windows Server vNext | Tagged: , , , , , | 3 Comments »

Working in the Datacenter – Add-DVDDrive does not work correctly in Windows Server 2016 TP4 (or in Windows 10)

Posted by Mikael Nystrom on December 17, 2015

Update 2015-12-17 : This is now a confirmed bug, and as soon as I know more I will update this post.

It seems to be a bug, hopefully it will be fixed soon. The issue is very simple. If you try to run Add-VMDvdDrive the –path must be specified, in previous version that could be left alone. This problem is more common when you create VM Gen 2, since it does not have a DVD by default, and yes when we build VM’s they usually have a empty DVD for various reasons. According to help in the command let, there is no differences in the cmdlet between 1.1 and 2.0, but in reality it is.

The Issue

The problem is that when using the command Add-VMDvdDrive -VMName $VMName it fails with Add-VMDvdDrive : Exception of type ‘System.ArgumentException’ was thrown because it does not have a path, so i have seen workarounds when you create a small ISO and mount that and then you can remove that, but that sucks. There are some other issues as well.

image
The issue.

The Workaround

Luckily there is 2 different PowerShell modules, 1.1 for older OS and 2.0 for Windows 10/Windows server 2016 TP4 so the only thing you need to do is unload the new PowerShell module for Hyper-V and load the old one, and when you are done, you can load the new module again.

(if you would like to know why there is 2 versions, here you go: http://blogs.msdn.com/b/virtual_pc_guy/archive/2015/11/16/why-are-there-two-hyper-v-powershell-modules-in-windows-10.aspx)

image
We run this in the beginning of the script to replace the module.

image
We run this in the end of the script to restore the module.

/mike

Here is the code on GHitHub

Posted in Datacenter, Hyper-V, PowerShell, Windows 10, Windows Server 2016 | Tagged: , , , | 1 Comment »

Working in a Datacenter – Nested Hyper-V or Running Hyper-V in Hyper-V

Posted by Mikael Nystrom on November 21, 2015

image

There are many reason where it make sense to run Hyper-V in Hyper-V, one of them being to enable Credential Guard (VSM) in Windows Server 2016 TP 4 and later. For training, demos, test. R&D it is great. For Windows Server 2016 TP4 it needs to be enable and configured to work and that means PowerShell. Currently there are also some limitations.

On the Host:

Device Guard Disable
Credential Guard Disable
Hyper-V Enabled
Hardware Intel VT-x
Windows Version Build 10565 or greater

 

In the VM:

Dynamic Memory No
Change memory while VM is running No
Using any kind of Checkpoint No
Live Migration No
Save/Resume No

 

You can read the fine print here: https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/user_guide/nesting

The PowerShell Function/Script:

This script will enable Nested Hyper-V an a VM
Invoke-WebRequest "https://raw.githubusercontent.com/DeploymentBunny/Files/master/Tools/Enable-NestedHyperV/EnableNestedHyperV.ps1" -OutFile ~/EnableNestedHyperV.ps1
Import-Module ~/EnableNestedHyperV.ps1
Enable-NestedHyperV -VMname TEST100
This Script (Provided be Microsoft) will verify configuration
Invoke-WebRequest "https://raw.githubusercontent.com/Microsoft/Virtualization-Documentation/master/hyperv-tools/Nested/Get-NestedVirtStatus.ps1" -OutFile ~/Get-NestedVirtStatus.ps1
~/Get-NestedVirtStatus.ps1

/mike

Posted in Datacenter, Hyper-V, Windows 10, Windows Server, Windows Server 2016, Windows Server vNext | Tagged: , , , , | 1 Comment »

PowerShell is King – Compress, Compact, Optimize VHD and VHDX files

Posted by Mikael Nystrom on June 15, 2015

I was reading a thread at Facebook in our user group, someone was trying to compress/compact/optimize a VHD(VHDX files but the result was depressing, the amount of reclaimed space was zero and that is kind of low… Now there is a good explanation for that, when using the UI there is no way to configure it and the UI also don’t inform you that the ONLY way to get it small is to mount it in Read Only mode. It really has to be mounted, otherwise there is now way to see “inside” the disk and to get rid of all the Zero blocks. It does not hurt if you also run defrag and cleanup inside the VM before, but the most important thing is that it needs to be mounted.

The documentation for the PowerShell command says:

image

The Script:

So, to make things easy for my friends in the User Group I created a simple script that will find the disks for the VM, check if the VM is running and if not mount each file in read only mode with no drive letter, optimize the VDH and dismount it. So the output of the script looks like this when running using –verbose

image

and here is how the script looks like:

image

and you can download the script here…http://1drv.ms/1IES3pB

/mike

Posted in Hyper-V, PowerShell | Tagged: , , | 6 Comments »

Windows Server vNext – Hyper-V in Hyper-V

Posted by Mikael Nystrom on May 1, 2015

Yes, it is true

image

Continue reading the story at the source for much more information!!!

http://www.hyper-v.nu/archives/hvredevoort/2015/05/nested-hypervisor-in-windows-server-vnext/

Posted in Hyper-V, Windows Server vNext | Tagged: , | Leave a Comment »

Nice to Know – HP FlexFabric 10GB 2-port 534FLB Adapter can cause network issues using NVGRE

Posted by Mikael Nystrom on February 5, 2015

Today I was working at a customer site, setting up a NVGRE Gateway in a Fabric domain. Install, configuration, all went nice and smooth until we should test and verify that the VM’s could access the network, found a miss configuration and then, hey it was working, well TCP was working but NOT UDP, wtf??? Some troubleshooting (Google and Bing and some cursing) and it seems to be some various obscure things, some hotfixes but then we found something that actually worked…

The issue: Encapsulated Task Offloading

I’m pretty sure that the idea behind it is all good, but of course as all “great” things, it does not work in this combination.

imageimage
Here you can se the setting that needs to be disabled and you can also see the driver version and date that was in place.

The Solution: Disable it!

But, if you disable it on every hyper-v host (not only the hosts running the NVGRE gateway), it starts working. At the time we could not find any other solution then to disable it.

In this case the customer (and you know how you are) was kind enough to let me post the script that was used to disable this “amazing” technology.

image

or here in plain text form


$Nics = Get-NetAdapterAdvancedProperty -DisplayName “Encapsulated Task Offload”

foreach($Nic in $Nics)
{
Set-NetAdapterEncapsulatedPacketTaskOffload -Name $Nics.Name -EncapsulatedPacketTaskOffloadEnabled:$false
}


/Mike

Posted in Fabric, Hyper-V, SCVMM, System Center Configuration Manager 2012 R2 | Tagged: , , | Leave a Comment »

Nice to Know – Improve Bare Metal Deployment success rate in System Center Virtual Machine Manager

Posted by Mikael Nystrom on November 5, 2014

Bare Metal Deployment in SCVMM is a bit different compared to everything else, since it is using a push method. So instead of having some kind of client application controlling the deployment, the SCVMM server is controlling the OS Deployment. There could be issues, since SCVMM is building team and switches and there is a chance that SCVMM will loose connectivity to the host and the Bare Metal Deployment stops. In many case that is related to DNS and DNS cache, since that is the method used to be able to connect to the host during deployment. By decreasing the DNS cache timeout on the SCVMM server the success rate will improve very, very much.

How to fix it?

Logon to your SCVMM server and execute the following PowerShell commands to set the DNS Cache to a minimum and restart the DNS Cache services

New-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters" -Name "MaxCacheTtl" -Value 5 -PropertyType "DWORD" -Force
New-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters" -Name "MaxNegativeCacheTtl" -Value 5 -PropertyType "DWORD" -Force
Restart-Service -Name Dnscache -Force -Verbose

/mike

Posted in Hyper-V, OS Deployment, SCVMM | Tagged: , , , | Leave a Comment »

Nice to Know–Microsoft Virtual Machine Converter 3.0 released to web

Posted by Mikael Nystrom on October 13, 2014

image

Now with P2V, yes!

New Features in MVMC 3.0
The 3.0 release of MVMC adds the ability to convert a physical computer running Windows Server 2008 or above server operating systems or Windows Vista or above client operating systems to a virtual machine running on Hyper-V host.

Standard stuff is:

  • Converts virtual disks that are attached to a VMware virtual machine to virtual hard disks (VHDs) that can be uploaded to Microsoft Azure.
  • Provides native Windows PowerShell capability that enables scripting and integration into IT automation workflows.
    Note The command-line interface (CLI) in MVMC 1.0 has been replaced by Windows PowerShell in MVMC 2.0.
  • Supports conversion and provisioning of Linux-based guest operating systems from VMware hosts to Hyper-V hosts.
  • Supports conversion of offline virtual machines.
  • Supports the new virtual hard disk format (VHDX) when converting and provisioning in Hyper-V in Windows Server® 2012 R2 and Windows Server 2012.
  • Supports conversion of virtual machines from VMware vSphere 5.5, VMware vSphere 5.1, and VMware vSphere 4.1 hosts Hyper-V virtual machines.
  • Supports Windows Server® 2012 R2, Windows Server® 2012, and Windows® 8 as guest operating systems that you can select for conversion.
  • Converts and deploys virtual machines from VMware hosts to Hyper-V hosts on any of the following operating systems:
  • Windows Server® 2012 R2
  • Windows Server® 2012
  • Windows Server 2008 R2 SP1
  • Converts VMware virtual machines, virtual disks, and configurations for memory, virtual processor, and other virtual computing resources from the source to Hyper-V.
  • Adds virtual network interface cards (NICs) to the converted virtual machine on Hyper-V.
  • Supports conversion of virtual machines from VMware vSphere 5.5, VMware vSphere 5.0, and VMware vSphere 4.1 hosts to Hyper-V.
  • Has a wizard-driven GUI, which simplifies performing virtual machine conversions.
  • Uninstalls VMware Tools before online conversion (online only) to provide a clean way to migrate VMware-based virtual machines to Hyper-V.
    Important MVMC takes a snapshot of the virtual machine that you are converting before you uninstall VMware Tools, and then shuts down the source machine to preserve state during conversion. The virtual machine is restored to its previous state after the source disks that are attached to the virtual machine are successfully copied to the machine where the conversion process is run. At that point, the source machine in VMware can be turned on, if required.
    Important MVMC does not uninstall VMware Tools in an offline conversion. Instead, it disables VMware services, drivers, and programs only for Windows Server guest operating systems. For file conversions with Linux guest operating systems, VMware Tools are not disabled or uninstalled. We highly recommend that you manually uninstall VMware Tools when you convert an offline virtual machine.
  • Supports Windows Server and Linux guest operating system conversion. For more details, see the section “Supported Configurations for Virtual Machine Conversion” in this guide.
  • Includes Windows PowerShell capability for offline conversions of VMware-based virtual hard disks (VMDK) to a Hyper-V–based virtual hard disk file format (.vhd file).
    Note The offline disk conversion does not include driver fixes.

Posted in Hyper-V, SCVMM | Tagged: , | 1 Comment »