Monitor Hyper-V with the command line (Part 2): Basic monitoring commands

In this article, we will learn how to access the virtual machine list and see general information about virtual machines with simple PowerShell statements. We will also look at stop commands and start virtual machines from the command window.

TipsMake.com - In this article, we will learn how to access the virtual machine list and see general information about virtual machines with simple PowerShell statements. We will also look at stop commands and start virtual machines from the command window.

>>>Monitor Hyper-V with the command line (Part 1): Install the monitoring library

If you have read the first part of this series, you already know how to install the Hyper-V monitoring library. Now is the time to reap the benefits of the installation process by monitoring Hyper-V from PowerShell.
Each time you open PowerShell, you will have to enter the Hyper-V monitoring library before you can use any of the commands below. The command to enter the monitoring library is:

Import-Module 'C: Program FilesModulesHypervHyperv.psd1'

Basic monitoring commands

Hyper-V monitoring library supports a lot of commands, here are some basic commands that users can perform from PowerShell.

If you want to see the virtual machines that exist on the Hyper-V server, use the following command:

Get-VM

This command displays a table representing each virtual machine and host name that the virtual machine currently exists on (this is particularly convenient for large clusters that a virtual machine might be running on a particular cluster). . The Get-VM command also shows the user the current state of each virtual machine as well as the time the virtual machine is running. The table also contains an owner field (owner field).

Now you know how to get a list of virtual machines on your server. Assuming you want to see some more information about a specific virtual machine, use the Get-VMSummary statement with the name of the virtual machine you want to check.

The following figure shows the operation of the Get-VM and Get-VMSummary commands. As you can see, the Get-VMSummary statement displays the virtual machine name, IP address, operating system, and some other statistics.

Picture 1 of Monitor Hyper-V with the command line (Part 2): Basic monitoring commands

In addition, there are several variations of these statements. For example, if you want to get a list of virtual machines from a specified server named Main, just add the '-Server' parameter after the Get-VM command:

Get-VM-Server Main

Similarly, we can get summary information from a virtual machine on the remote server. For example, if you want to see information about a virtual machine named DNS on the Main server, use the command:

Get-VMSummary DNS-Server Main

Picture 2 of Monitor Hyper-V with the command line (Part 2): Basic monitoring commands

Of course, the Hyper-V monitoring library is even more useful than just collecting virtual machine information. It can also launch and stop virtual machines with the command line. The command we use to launch the virtual machine is: Start-VM .

When executing this command, you will receive a background activity warning message, as shown below. This message can be ignored because it simply shows that the virtual machine is starting and that the initialized WMI has been lined up.

Picture 3 of Monitor Hyper-V with the command line (Part 2): Basic monitoring commands

In fact, if you read the warning carefully, you will notice that PowerShell gives you a WMI identifier as well as the cmdlets that will be used to check the status.

Picture 4 of Monitor Hyper-V with the command line (Part 2): Basic monitoring commands

Use the Stop-VM command to stop the virtual machine. The command basically pushes the virtual machine into a state of being stopped, so to turn off the virtual machine, it is better to use the invoke-VMShutdown command. This command actually tells the virtual machine operating system to perform a shutdown. Of course, this statement is designed to be used for virtual machines using the Windows operating system.

In the picture below, you can see that I first entered the Stop-VM command. When PowerShell asks if I really want to stop the virtual machine, I cancel it by pressing N. Then, use the Invoke-VMShutdown command (with the virtual machine name) to start the shutdown process. Again, PowerShell asked me if I really wanted to do this. This time I entered Y and the shutdown process started. Finally, check that the virtual machine is turned off with the Get-VM command.

Picture 5 of Monitor Hyper-V with the command line (Part 2): Basic monitoring commands

Now you know how to check the virtual machine's overall information and how to start and stop the virtual machine from the command line interface. In Part 3, I will show you two troubleshooting commands, PingVM and TestVmHeartBeat. Next are some tricks to adjust memory allocation for virtual machines.

Update 26 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile