Last updated by at .

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

Tag: PowerShell

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.

 

 

 



PowerShell SSH Session

Using SSH with PowerShell

Microsoft announced that they will support SSH using PowerShell in Windows 10. Until now Microsoft has a good solution for this, there is a third party solutions called Posh-SSH. To use SSH in PowerShell you first have to install the Posh-SSH PowerShell Module from the PowerShell Gallery. Make sure you are running Windows 10 or you have the Windows Management Framework 5 installed.

You can now find the Posh-SSH Module and install it:

PowerShell SSH Installation

You now have several PowerShell SSH cmdlets available:

PowerShell SSH cmdlets

Now you can create a new SSH Session using the following cmdlet (Password based authentication)

PowerShell SSH Session

You can now simply run commands against this session or use SCP to copy files.

PowerShell SSH Commands

 



PowerShell New-Guid

Create GUID using PowerShell

PowerShell version 5 brings a lot of new cmdlets which make our lives easier and our code cleaner. One of them is the New-GUID cmdlet. Before we had this cmdlet we had to use the .NET command to create a new GUID:

Now with PowerShell 5 we can use simply the new cmdlet:



Get-NetIPConfiguration

Basic Networking PowerShell cmdlets cheatsheet to replace netsh, ipconfig, nslookup and more

Around 4 years ago I wrote a blog post about how to Replace netsh with Windows PowerShell which includes basic powershell networking cmdlets. After working with Microsoft Azure, Nano Server and Containers, Powershell together with networking becomes more and more important. I created this little cheat sheet so it becomes easy for people to get started.

Basic Networking Information with PowerShell

Get-NetIPConfiguration

Get the IP Configuration (ipconfig with PowerShell)

List all Network Adapters

Get a spesific network adapter by name

Get more information VLAN ID, Speed, Connection status

Get driver information

Get adapter hardware information. This can be really usefull when you need to know the PCI slot of the NIC.

Disable and Enable a Network Adapter

Rename a Network Adapter

IP Configuration using PowerShell

Get-NetIPAddress

Get IP and DNS address information

Get IP address only

Get DNS Server Address information

Set IP Address

or if you want to change a existing IP Address

Remove IP Address

Set DNS Server

Set interface to DHCP

Ping with PowerShell

Test-NetConnection Ping

How to Ping with PowerShell

Get some more details from the Test-NetConnection

Ping multiple IP using PowerShell

Tracert

PowerShell Tracert

Tracert with PowerShell

Portscan with PowerShell

PowerShell Portscan

Use PowerShell to check for open port

NSlookup in PowerShell

PowerShell NSlookup

NSlookup using PowerShell:

Route in PowerShell

PowerShell Route

How to replace Route command with PowerShell

NETSTAT in PowerShell

PowerShell Netstat

How to replace NETSTAT with PowerShell

NIC Teaming PowerShell commands

Create a new NIC Teaming (Network Adapter Team)

SMB Related PowerShell commands

SMB PowerShell SMB Client Configuration

Get SMB Client Configuration

Get SMB Connections

Get SMB Mutlichannel Connections

Get SMB open files

Get SMB Direct (RDMA) adapters

Hyper-V Networking cmdlets

Hyper-V PowerShell Get-VMNetwork Adapter

Get and set Network Adapter VMQ settings

Get VM Network Adapter

Get VM Network Adapter IP Addresses

Get VM Network Adapter Mac Addresses

I hope you enjoyed it and the post was helpful, if you think something important is missing, please add it in the comments.



Azure Remote Server Management Nano Server

Manage Nano Server and Windows Server from Azure using Remote Server Management Tools

Today Microsoft announced the preview of the Remote Server Management Tools hosted in Azure, written by Kriti Jindal, a program manager on the Server management tools team. This service allows you to manage your servers directly from Azure using a web-based HTML5 portal. I personally think that this could replace Server Manager and allows you to easily manage non-GUI servers such as Windows Server Core and Nano Server. This is the first public preview of the Remote Server Management Tools and it limited right now to manage Windows Server 2016 Technical Preview server, hosted on-prem or in Microsoft Azure. The Remote Server Management Tools today include the following features:

  • View and change system configuration
  • View performance across various resources and manage processes and services
  • Manage devices attached to the server
  • View event logs
  • View the list of installed roles and features
  • Use a PowerShell console to manage and automate

Overview

To remotely manage your Windows Server from Azure, you have to deploy a Remote Server Management Gateway into your network. This can be a Windows Server 2012 R2 Server running the WMF 5.0 (Windows Management Framework 5.0) or Windows Server 2016 with no additional preparation. You also need a Microsoft Azure subscription and an account.

Microsoft Azure Server Management Tools Topology

The gateway will handle the connection to Azure, so the Remote Server Management Gateway needs connection to the internet. The managed servers do not need a direct connection to the internet, the gateway will connect to the managed server. With that, the gateway need connection to the sever which will be managed by Azure.

Setup Server Management Tools

Well to set this up some steps are required, first create a new server for the Remote Server Management Gateway. In my case I installed a new Windows Server 2016 virtual machine. I made sure I could connect to the internet and it has the lastest updates installed.

Microsoft Azure Server Management Tools New Connection

After I created the virtual machine I logged in to the Azure portal and added a new Server Management Tools Connection. You can search “Server management tools” in Marketplace or navigate to it: Marketplace -> Management -> More -> Server management tools. This will also create the first Server Management Tools Gateway for your connection.

Microsoft Azure Server Management Tools Connection

After the connection is created you can see the connection and but you will get the information that the gateway is not ready. As the next step you will configure the gateway on the prepared server.

Microsoft Azure Server Management Tools Gateway

Under the Server Management Tools Gateway blade you can find a setup for the gateway which will generate a custom install package for your gateway. You can copy this link to the server and download this package and install it.

  1. Allow gateway updates to be installed automatically (recommended), or choose to install updates manually. You may change this later under gateway settings.
  2. Click the below to generate a customized gateway deployment package link.
  3. Use the generated link to download the gateway deployment package now, or copy the link URL to download the package later from the machine on which you intend to install the package.
  4. From the machine that you want to designate as the gateway, unzip the package and run GatewayService.MSI.
  5. Once the gateway installation completes, return to the Microsoft Azure portal and reopen your Server management tools connection.
  6. You should now be able to manage your Windows Server 2016 machine if the Microsoft Azure portal can reach it through the gateway.

Azure Remote Server Management Gateway Installer

After you have installed the Remote Server Management Gateway package on your gateway server you can see the connection in the Azure portal.

Azure Remote Server Management Nano Server

Now you start remote manage your server. As mentioned before, this is really handy if you want to manage Server Core or Nano Server.

Additional Stuff:

There are some additions for the configuration if you want to manage servers in a workgroup environment:

In order to manage workgroup machines (e.g. non-domain-joined Nano Servers), run this command as an administrator on the Server management tools gateway machine:

winrm set winrm/config/client @{ TrustedHosts=”<<IP address>>” }

When creating a Server management tools connection to the workgroup machine, use the machine’s IP address as the computer name.

Additional connectivity requirements

If you wish to connect using the local Administrator account, you will need to enable this policy on the target machine by running the following command in an administrator session on the target machine:

REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1

If you wish to connect to a workgroup machine which is not on the same subnet as the gateway, run the following command in an administrator session on the target machine:

NETSH advfirewall firewall add rule name=”WinRM 5985″ protocol=TCP dir=in localport=5985 action=allow

Remote Management Server Tools Features

Azure Remote Server Management PowerShell

As mentioned the Remote Management Server Tools bring some really cool web-based management features. One of my favorites is the web-based PowerShell console.

  • Device Manager
  • PowerShell Console
  • Computer Configuration (Name, Domain,…)
  • Network Configuration
  • Task Manager
  • Process
  • Registry Editor
  • Roles and Features
  • Services
  • Local Administrators
  • Updates Management (coming soon)
  • Shutdown / Restart

More Information

 

 



PowerShell Compress-Archive

Compress or Expand ZIP Archive using PowerShell

I was blogging about some of the new features of PowerShell 5 in several blog posts. Another great enhancement of PowerShell v5 is the Compress-Archive and the Expand-Archive cmdlets which allow you to compress or expand a ZIP archive.

To simply create a new ZIP archive using PowerShell you can use the following cmdlet:

To unzip the ZIP Archive you can use the following cmdlet: