首页 > 其他 > 详细

实用——PowerCLI (一)

时间:2014-02-12 21:39:46      阅读:629      评论:0      收藏:0      [点我收藏+]

 

近来,安装过较多产品,深感疲乏,犹如农民伯伯在家研究种子,却不种到地里,还不如往地里丢蚕豆,任其生长,还有收成。

于是,想做一些拿来就能用的文档,方便学习,《实用——PowerCLI》系列就是这样。

 

现在没有大纲,写到哪,算到哪,形式为命令+截图。

 

一、Powercli基础命令

二、待续…

 

Powercli是一个命令行自动化和脚本工具,它为VMware公司的vSphere和vCloud产品提供了一个的Windows PowerShell接口。

Powercli包括高级命令,和低级别vSphere和vCloud API的访问

 

Powercli的安装在前面博客介绍过,这里提供链接http://virtualbox.blog.51cto.com/531002/978907

 

在VMware Community社区的WorkShop里,包括了很多基础的脚本例子,我们先从这里开始

1、默认界面

bubuko.com,布布扣

 

2、

# To see what PowerCLI can do, start with Get-VICommand
# 查看PowerCLI能做哪些
Get-VICommand

bubuko.com,布布扣

 

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*

 

bubuko.com,布布扣

4、

# You can also use "help" to narrow your search. Let‘s say you want to do something with virtual switches.
#你还可以使用”help”来缩小搜索范围, 让我们来搜小搜索virtualswitchs的访问 。
help *virtualswitch*

bubuko.com,布布扣

# 查看虚拟交换机帮助

help Get-VirtualSwitch

bubuko.com,布布扣

5、

# Or maybe you care about firewall rules.
#或者你可以看下防火墙相关的命令
help *firewall*

 

bubuko.com,布布扣

6、

# Cmdlets exist to get all your favorite objects.
#Cmdlets存在一些你很感兴趣的对象
Get-Datacenter
Get-VMHost
Get-Cluster
Get-VM

 

7、

# These commands are made to work with each other.You can easily use a sequence of them to filter.
#这些命令是相互作用的 ,你可以很轻松的进行过滤选择
Get-VMHost

 

bubuko.com,布布扣
8、

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、

# We can easily identify the datastore a VM is on.
#我们可以很容易识别虚拟机在哪个数据存储上
Get-VM vCenter
Get-VM vCenter | Get-Datastore

 

bubuko.com,布布扣

10、

# We can even go the other way.
#我们甚至可以走另外一条路,查看数据存储上有哪些虚拟机
Get-Datastore 20storage | Get-VM

 

 

bubuko.com,布布扣

11、

# 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 *

 

bubuko.com,布布扣

bubuko.com,布布扣

12、

# Some objects are rich with properties.
#一些项目有丰富的内容
Get-VM | Format-List *

 

bubuko.com,布布扣

13、

 

#可以延伸下,客户说只看指定的虚拟机AD-25的虚拟机信息。
Get-VM AD-25 | Format-List *

bubuko.com,布布扣

14、

# Use the Select cmdlet to choose just the stuff you care about.
#使用cmdlet去选择你关心的东西
Get-VM  | Select Name, Host, NumCpu, MemoryMB, HARestartPriority | Format-Table

 

bubuko.com,布布扣

 

 

 

下载地址(最新版本未PowerCli 5.5,Get-PowerCLIVersion)

https://developercenter.vmware.com/web/dp/sdk/55/vsphere-powercli

本文出自 “virtualbox” 博客,请务必保留此出处http://virtualbox.blog.51cto.com/531002/1358364

实用——PowerCLI (一)

原文:http://virtualbox.blog.51cto.com/531002/1358364

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!