免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1942 | 回复: 0
打印 上一主题 下一主题

[Microsoft虚拟化] 使用Windows2008内置的POWERSHELL管理HyperV Demo [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-16 14:30 |只看该作者 |倒序浏览
You can use Windows PowerShell to manage virtual machines running onHyper-V servers running Server Core, but you must run your scriptsremotely from a computer that has Windows PowerShell installed on it.In addition, your Windows PowerShell scripts can be used only to accessthe WMI interface on the targeted Server Core installation. This meansthe primary Windows PowerShell cmdlet you will use to manage virtualmachines running on Server Core is the Get-WmiObject cmdlet, which alsohas the associated gwmi alias in Windows PowerShell.

Here are a few examples of how you can use Windows PowerShell scriptsto manage virtual machines running on a Server Core installation. Notethat these scripts are presented as samples and may need to becustomized to work in your environment.

Displays the State of All Virtual Machines


$VMState=@{2="Running" ; 3="Stopped" ; 32768="Paused" ; 32769="Suspended";
32270="Starting" ; 32771="Snapshotting" ; 32773="Saving" ; 32774="Stopping" }
get-wmiobject -computername localhost -Namespace root\Virtualization
-query "Select * from MSVM_Computersystem where Description like
'%Virtual%' " | format-table -autosize @{Label=”VM Name”;
expression={$_.elementName}}, Description, @{Label =”VM State”;
expression={$VmState[$_.EnabledState]}}


Creates a Snapshot of All Virtual Machines

$VSMgtSvc=Get-WmiObject -ComputerName localhost
-NameSpace "root\virtualization"
-Class "MsVM_virtualSystemManagementService"
get-wmiobject -computername localhost -Namespace root\Virtualization
-query "Select * from MSVM_Computersystem where Description like
'%Virtual%' " | foreach-object {$VSMgtSvc.psbase.invokeMethod
("CreateVirtualSystemSnapshot",@($_,$Null,$null)) }


Saves the State of All Running Virtual Machines

$VSMgtSvc=Get-WmiObject -ComputerName localhost -NameSpace "root\
virtualization" -Class "MsVM_virtualSystemManagementService"
Get-WmiObject -computername Localhost -NameSpace "root\virtualization"
-Query "Select * From MsVM_ComputerSystem Where Caption Like 'Virtual%'
and EnabledState = 2" | foreach-Object {$_.RequestStateChange(32769) }
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP