Last updated by at .

  • Hyper-V 2016
    What's new in Hyper-V 2016
  • Microsoft Azure
    Microsoft Azure

Tag: PowerShell

Windows Defender PowerShell

How to disable and configure Windows Defender on Windows Server 2016 using PowerShell

Windows Server 2016 comes standard with built-in Anti-Malware called Windows Defender like Windows 10 Client. And per default, Windows Defender is active and has also turned on Real-Time Protection by default. In Windows Server 2016 Desktop Experience you can disable and configure Windows Defender using the UI or PowerShell, in the Windows Server 2016 Core version or on Nano Server you only have PowerShell available. Here are some quick command how you can do this:

Check the Windows Defender Configuration and Settings:

Turn off Windows Defender Real-Time Protection using PowerShell

Turn onWindows Defender Real-Time Protection using PowerShell

Add a File path exclusion:

Add process exclusion

 

I hope this helps you to easily configure Windows Defender on Windows Server 2016. Btw. This also works on Windows Defender on Windows 10.



VM Network Adapter

PowerShell One-liner to list IP Addresses of Hyper-V Virtual Machines

Here a very quick PowerShell command to list all the Virtual Network Adapters, including IP Addresses of Virtual Machines running on a Hyper-V Host.

This will give you a list of all Virtual Machines running on Hyper-V Server called “HyperV01”



VCNRW Nano Server and Container

Video: VCNRW – Virtualization Community NRW recording about Nano Server and Windows Containers

A couple of weeks ago I had the chance to speak at the VCNRW – Virtualization Community NRW community event at the Microsoft Offices in Cologne. The recording of this session (in German) is now available on Microsoft Channel 9.

Nano Server and Containers (on Microsoft Channel 9)

Have a look at the latest Cloud Technologies from Microsoft. Learn about the next Microsoft Cloud Platform Server called Nano Server and Windows Containers. Both solutions are built for the future and will fundamentally change how we do IT. Learn why we need Nano Server and Windows Containers and how we deploy, manage and operate them.



cmd clip

Pipe cmd prompt commands into the clipboard

This is a very all but very useful command if you work with the Windows Command Prompt. This allows you to output text from commands into the Windows clipboard.

Scott Hanselman from Microsoft just reminded the community about this feature, which is available in Windows since Windows Vista.

PowerShell v5 got some similar command using Set-Clipboard and Get-Clipboard.



unatted xml file for VM

Add unattend.xml to VHDX File for VM automation

If you for example don’t have System Center Virtual Machine Manager or another tool to create Virtual Machine Templates and automate the deployment, you can also do this using Sysprep, PowerShell and an unattend.xml file to automate or simplify the Virtual Machine creation process. In other blog posts I already wrote how you can sysprep Virtual Machines or how you can create Hyper-V Virtual Machines using PowerShell. In this post I will show you how you can add an unattend.xml file to your VHD or VHDX so your virtual machine gets some default settings like regional information.

Here we have a basic unattend.xml file. If you want to enhance it, or create your own, you can also use the Windows ADK.

To use this unattend.xml you first have to sysprep a virtual machine and create a sysprep VHD file. After that you can mount the VHDX file and insert the unattend.xml file to the VHD. Copy the unattend.xml file to the following location: D:\Windows\Panther (in my case the VHD was mounted as D drive).

You can mount the VHDX using the UI or PowerShell:

There are more paths as well. You can check out the Windows Setup Automation Overview on TechNet where you can see all the possible paths to place the unattend.xml file.



Azure PowerShell Installing

How to Install the Azure PowerShell Module

Well if you are working with Microsoft Azure you may need the PowerShell Modules for automation and some settings which are only available in PowerShell. With the latest releases you can install the Azure PowerShell Module in several different ways.

Install Azure PowerShell

For me using the PowerShell Package Management and the PowerShell Gallery is may the easiest and fastest way to install it. In Windows 10 or a computer with the Windows Management Framework 5 installed, you can use the following PowerShell cmdlets to install it:

Microsoft Azure Resource Manager (new Portal):

And you can use the following command to login:

If you are using it against the classic Azure Portal you can use the following:

And you can use the following command to login:

 

You can also see the Azure PowerShell Modules and versions using the PowerShell Package Management:

Azure PowerShell Module

 

 



Hyper-V NAT Switch

Set up a Hyper-V Virtual Switch using a NAT Network

A couple of months ago I wrote a blog post about how you can create a new Hyper-V NAT Switch. Now this worked fine in some early Windows 10 builds, but Microsoft removed the parameter for the NAT Switch in some Windows 10 Insider builds. Today Sarah Cooley PM at the Microsoft Hyper-V team, documented how you can do this using newer Windows 10 builds.

Requirements:

  • Windows 10 and Windows Server 2016 build 14295 or later
  • Enabled Hyper-V role
  • PowerShell, since this setting is not available in the UI right now

Hyper-V NAT Switch

Create a new Hyper-V Virtual Switch

Configure the NAT Gateway IP Address

This configures the Virtual Network Adapter which was created while creating the Internal Virtual Hyper-V Switch.

Now you can 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.

Hyper-V Virtual Switch NAT Configuration

Create a new NAT forwarding

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.

[PowerShell]

Add-NetNatStaticMapping -NatName “VMSwitchNat” -Protocol TCP -ExternalIPAddress 0.0.0.0 -InternalIPAddress 172.21.21.2 -InternalPort 80 -ExternalPort 80

[PowerShell]

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.

[PowerShell]

Add-NetNatStaticMapping -NatName “VMSwitchNat” -Protocol TCP -ExternalIPAddress 0.0.0.0 -InternalIPAddress 172.16.0.3 -InternalPort 80 -ExternalPort 82

[PowerShell]

This also works with Windows and Hyper-V Containers.