PowerShell often provides greater flexibility and better efficiency when it comes to performing operations you’d otherwise run through GUI tools such as Hyper-V Manager and SCVMM console.

While System Center Virtual Machine Manager is a useful product that can help you manage virtualization hosts from a central machine, for environments where SCVMM is not deployed and in situations where you need to perform Hyper-V-related operational tasks on multiple Hyper-V hosts, you have two choices. Windows Server Tutorials

First, you can use Hyper-V manager and connect to a remote Hyper-V server and then perform the required actions. The downside though in using Hyper-V manager to connect to each Hyper-V host and then performing the required tasks is that it might take a considerable amount of time.

If you are familiar with PowerShell, it becomes easier to perform the same tasks on multiple Hyper-V hosts in little to no time. All you have to do is simply change the Hyper-V host name against which you want to run the PowerShell commands. In today’s Server Tutorial, we are going to explain the use of the “-ComputerName” parameter to execute Hyper-V PowerShell commands against a remote Hyper-V host.

If you wish to see a list of Hyper-V PowerShell PowerShell cmdlets, what you can do is run this command: Get-Command -Module Hyper-V | Out-GridView. Once this command is executed, you will be presented with a data grid shown on the desktop that includes the Hyper-V cmdlets.

Creating a New Virtual Machine on a Remote Hyper-V Host

If you need to create a new virtual machine on a remote Hyper-V host, you can use the New-VM PowerShell cmdlet. The PowerShell script to create a new virtual machine looks like this:

$VMNameVariable = "SQLVM"
$VM = @{
Name = $VMNameVariable
MemoryStartupBytes = 4147483648
Generation = 1
NewVHDPath = "E:\VMs\$VMNameVariable\$VMNameVariable.vhdx"
NewVHDSizeBytes = 43687091200
BootDevice = "VHD"
Path = "E:\VMs\$VMNameVariable"
SwitchName = (Get-VMSwitch).Name[0]
New-VM @VM -ComputerName "Hyper-VHost1"

As you can see in the above PowerShell script, the $VM variable holds required information for a new virtual machine and the New-VM PowerShell cmdlet creates a new virtual machine on the remote Hyper-V host specified in the “-ComputerName” parameter. If you wish to create another virtual machine on a different remote Hyper-V host, simply change the Hyper-V host name specified in the “-ComputerName” parameter.

Enabling Dynamic Memory on a Remote Virtual Machine

Let’s say you need to configure the dynamic memory parameter on a virtual machine running on a remote Hyper-V host. Since Hyper-V modules offer the Set-VMMemory PowerShell cmdlet to work with memory parameters of a virtual machine, you can execute the following PowerShell command to modify the Dynamic Memory of a remote virtual machine:

Set-VMMemory SQLVM -ComputerName "Hyper-VHost1"
-DynamicMemoryEnabled $True -MinimumBytes 64MB -StartupBytes 256MB
-MaximumBytes 4GB -Priority 80 -Buffer 25

The above command enables Dynamic Memory for SQLVM running on a remote Hyper-V host named “Hyper-VHost1” and configures the required dynamic memory parameters such as minimum memory required, startup memory and the maximum memory that can be used by the virtual machine. This command also helps in setting up the virtual machine priority and buffer values.

Configuring Virtual Processors on Virtual Machine

To configure virtual processors for a virtual machine, you can use the Set-VMProcessor PowerShell cmdlet as shown in the command examples below:

Set-VMProcessor SQLVM -ComputerName "Hyper-VHost1" -Count 2 -Reserve 10 -Maximum 75 -RelativeWeight 200
Set-VMProcessor SQLVM -ComputerName "Hyper-VHost1" -CompatibilityForMigrationEnabled $true
Set-VMProcessor SQLVM -ComputerName "Hyper-VHost1" -CompatibilityForOlderOperatingSystemsEnabled $true

The first PowerShell command configures a virtual machine with two virtual processors, while the second command enables the processor compatibility for live migration. The third command configures the virtual machine to be compatible to run on older Hyper-V versions. Note that all three commands use the “-ComputerName” parameter, which specifies the Hyper-V host against which the commands are executed.

Updating Virtual Machine Version

PowerShell can save you a lot of time when it comes to updating the Integration Services version on multiple virtual machines. The Update-VMVersion cmdlet is capable of detecting the Integration Services version on a virtual machine and perform an update if required. For example, the PowerShell command below will update SQLVM to the most recent virtual machine version:

Update-VMVersion -Name "SQLVM" -ComputerName "Hyper-VHost1" -Force

If you need to check and update the version on multiple virtual machines, you can provide a list of virtual machines separated by commas as shown in the following command:

Update-VMVersion -Name "SQLVM, ExchangeVM, AzureConnectVM, OracleVM" -ComputerName "Hyper-VHost1" -Force

Source : serverwatch

Leave a Reply

Your email address will not be published. Required fields are marked *