Hyper-V群集中VM的一些基本操作

 1 #启动/关机
 2 Start-VM -Name "testVM"
 3 Stop-VM -Name "testVM" -Force
 4 Stop-VM -Name "testVM" -Confirm:$false
 5 #迁移VM
 6 $hv01_VM=@("vm001","vm002")
 7 Move-VM -Name $hv01_VM  -DestinationHost "HV02"
 8 #或者
 9 get-cluster "MSFC" | Move-ClusterVirtualMachineRole -name "vm001" -node "HV02"
10 
11 
12 命令格式:Get-VM <VM name> | Move-ClusterVirtualMachineRole -MigrationType Live -Node <target name> -Wait 0
13 
14 #例1:
15 $clusterName = "MSFC"
16 
17 $targetClusterNode = "HV02"
18 
19 $haVMs =@("vm001","vm001")
20 
21 Move-ClusterVirtualMachineRole -MigrationType Live -name $haVMs -Node $targetClusterNode -Wait 0
22 Move-ClusterVirtualMachineRole -MigrationType Quick -name $haVMs -Node $targetClusterNode -Wait 0
23 
24 #例2:
25 $targetClusterNode = Get-ClusterNode -Cluster $clusterName | Out-GridView -Title "Select Target Cluster Node"  -OutputMode Single
26 $haVMs = Get-ClusterGroup -Cluster $clusterName | Where-Object {($_.GroupType -eq "VirtualMachine") -and ($_.OwnerNode -ne $targetClusterNode.Name)}
27 $haVMs | Out-GridView -Title "Select VMs to Move" –PassThru | Move-ClusterVirtualMachineRole -MigrationType Live -Node $targetClusterNode.Name -Wait 0

#修改以w-命名的虚拟机的内存

   Set-VM -Name w-* -MemoryStartupBytes 1610612736 //(1.5G=1610612736)



 ●统计每台Hyper-V服务器上的运行的虚拟机(串行)

1 $HVServer=@('HV01','HV02')
2 foreach($hv in $HVServer)
3 {
4     $VM_Count=Invoke-Command -ScriptBlock { get-vm vm* | where-object{$_.State -eq "Running"} | sort-object Name | Select Name } -ComputerName $hv
5     write-host "$hv  -->  $($VM_Count.count)"
6 }
View Code

 

posted @ 2017-03-22 16:28  山的那一边  阅读(381)  评论(0编辑  收藏  举报