近来,安装过较多产品,深感疲乏,犹如农民伯伯在家研究种子,却不种到地里,还不如往地里丢蚕豆,任其生长,还有收成。
于是,想做一些拿来就能用的文档,方便学习,《实用——PowerCLI》系列就是这样。
现在没有大纲,写到哪,算到哪,形式为命令+截图。
Powercli是一个命令行自动化和脚本工具,它为VMware公司的vSphere和vCloud产品提供了一个的Windows PowerShell接口。
Powercli包括高级命令,和低级别vSphere和vCloud API的访问
Powercli的安装在前面博客介绍过,这里提供链接http://virtualbox.blog.51cto.com/531002/978907
在VMware Community社区的WorkShop里,包括了很多基础的脚本例子,我们先从这里开始
1、默认界面
2、
1
2
3
|
# To see what PowerCLI can do, start with Get-VICommand
# 查看PowerCLI能做哪些
Get-VICommand
|
3、
1
2
3
|
# There are more than 150 commands, called "cmdlets".That's a lot! You can narrow your search based on something that interests you.
#有超过150个叫“cmdlets”的命令行, 您可以根据你的兴趣缩小搜索范围
Help *VM*
|
4、
1
2
3
|
# You can also use "help" to narrow your search. Let's say you want to do something with virtual switches.
#你还可以使用”help”来缩小搜索范围, 让我们来搜小搜索virtualswitchs的访问 。
help *virtualswitch*
|
# 查看虚拟交换机帮助
help Get-VirtualSwitch
5、
1
2
3
|
# Or maybe you care about firewall rules.
#或者你可以看下防火墙相关的命令
help *firewall*
|
6、
1
2
3
4
5
6
|
# Cmdlets exist to get all your favorite objects.
#Cmdlets存在一些你很感兴趣的对象
Get-Datacenter
Get-VMHost
Get-Cluster
Get-VM
|
7、
1
2
3
|
# These commands are made to work with each other.You can easily use a sequence of them to filter.
#这些命令是相互作用的 ,你可以很轻松的进行过滤选择
Get-VMHost
|
1
2
3
4
5
|
Get-Cluster
mycluster |
Get-VMHost
# Or we can restrict VMs to a given host.
#或者我们可以限制虚拟机在指定的主机上
Get-VM
|
Measure-Object
Get-VMHost
esxi.tim.local |
Get-VM
|
Measure-Object
|
9、
1
2
3
4
|
# We can easily identify the datastore a VM is on.
#我们可以很容易识别虚拟机在哪个数据存储上
Get-VM
vCenter
Get-VM
vCenter |
Get-Datastore
|
10、
1
2
3
|
# We can even go the other way.
#我们甚至可以走另外一条路,查看数据存储上有哪些虚拟机
Get-Datastore
20storage |
Get-VM
|
11、
1
2
3
4
5
|
# Objects are formatted when they are printed to the screen.But, there may be more to them than what you see with default output.
#输出屏幕上时它们被表格化 ,但是,默认输出的比你想看的多
Get-Datastore
Get-Datastore
|
Format-Table
*
Get-Datastore
|
Format-List
*
|
12、
1
2
3
|
# Some objects are rich with properties.
#一些项目有丰富的内容
Get-VM
|
Format-List
*
|
13、
1
2
|
#可以延伸下,客户说只看指定的虚拟机AD-25的虚拟机信息。
Get-VM
AD-25 |
Format-List
*
|
14、
1
2
3
|
# Use the Select cmdlet to choose just the stuff you care about.
#使用cmdlet去选择你关心的东西
Get-VM
| Select Name, Host, NumCpu, MemoryMB, HARestartPriority |
Format-Table
|
下载地址(最新版本未PowerCli 5.5,Get-PowerCLIVersion)
https://developercenter.vmware.com/web/dp/sdk/55/vsphere-powercli
本文转自 tim2009 51CTO博客,原文链接:http://blog.51cto.com/virtualbox/1358364,如需转载请自行联系原作者