[Turn] Windows Server 2012 RC of Hyper-V 3.0 PowerShell Commands Explanation (03)

Source Address: http: //www.powershellfans.com/ p = 1258?

==============================================================

Today, we continue to look over command and VM-related. According to terms of the first article gives a list of VM is the command, followed by the turn of the commands in the Big Brother Get-VM debut.

Get-VM is simple to use, although there are three parameter sets, but in fact common set of parameters should be only one, that is, using a virtual machine name to get that set of parameters virtual machine object. If you need to get the object at the same time on multiple Hyper-V hosts, we need to specify the ComputerName parameter. DETAILED command execution results are as follows:

image

In just this example, I have a virtual machine named 08R2-CNSHTSTSVR01 in testserver and cnshhypervsvr02 two machines, thus showing the effect of the screenshot. What happens when I assume my Name parameter specifies the two Hyper-V hosts each virtual machine a name yet? We try to know:

image

Ah, I will complain. Well, then I would a stream of consciousness, how about a virtual machine to determine whether it exists on a Hyper-V host, that is, the so-called Custom Test-VM command, the default is no such command module of. We can write your own function code is as follows:

Function Test-VM
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory=$true,Position=1)]
[string[]]$Name,
[Parameter(Mandatory=$true,Position=2)]
[string[]]$ComputerName
)
Process
{
$results = @()
foreach ($cName in $ComputerName) {
foreach ($vName in $Name) {
$result = New-Object System.Management.Automation.PSObject
Try
{
$vm = Get-VM -ComputerName $cName -Name $vName -ErrorAction Stop
if ($vm -ne $null) {
$Existence = $true
} else {
$Existence = $false
}
}
Catch
{
#Display an error message
}
$result | Add-Member -NotePropertyName ComputerName -NotePropertyValue $cName
$result | Add-Member -NotePropertyName Name -NotePropertyValue $vName
$result | Add-Member -NotePropertyName Existence -NotePropertyValue $Existence
$results += $result
}
}
return $results
}

The results do not rely on:

image

Next we look at is the Measure-VM command. The role of the command is to generate usage reports virtual machine processors, memory, networking and storage. Before using this command, you must run the Enable-VMResourceMetering command to enable the virtual machine resource usage records. There is also need to pay attention to the point, by default, Enable- VMResourceMetering requires the user to enter the name of the virtual machine, to respect one or multiple virtual machines to enable resource usage records. We feel tired knock name, you can find using the Get-VM virtual machine you want to set, and then passed to the Enable-VMResourceMetering can through the pipeline, the command is very simple, Get-VM -Name 08R2-CNSHA * | Enable-VMResourceMetering. After completion you can run the Measure-VMResourceMetering look at the report.

image

The result is good, there is a parameter we need to pay attention, MeteringDuration, which is called the use of recording time. Because the assessment of the use of resources will take some time, you can use this value to determine whether the record can be used as a resource base. If you need to reset it, you need to run the Reset-VMResourceMetering, but if for some reason you need to disable the use of resource records, then you can run the Disable-VMResourceMetering, or can be disabled via batch pipeline.

image

The introduction to this end, mainly over the next Get-VM and the noun part is VMResourceMetering command, also followed with more exciting content, so stay tuned.

(update completed)

Reproduced in: https: //www.cnblogs.com/licheng/archive/2013/02/25/2931601.html

Guess you like

Origin blog.csdn.net/weixin_34337381/article/details/92628033