前面几部分主要介绍了基于Linux的ESX命令,这些命令可以直接在ESX主机上运行,也可以通过SSH远程连接管理。后面几部分主要介绍基于Windows下的Microsoft PowerShell命令,PowerCLI是为Windows PowerShell脚本语言而创建的嵌入单元。

       这个嵌入单元能让你快速轻松地将vSphere环境的所有方面进行自动化。借助vSphere PowerCLI,通过由200多个VMware专用cmdlets组合形成脚本,IT管理员可以自动执行所有的虚拟环境相关管理任务。对于虚拟化管理员而言,脚本无疑是非常实用的,因为它可以无需人为参与执行进程(这样可以释放IT管理员去做其它工作),而且在资源紧张的环境中可以用于规划在非高峰期完成某些任务,在执行大量重复性的烦杂工作时还可以避免人为错误的发生。

1.安装要求:

.net 2.0 Service Pack1

Window PowerShell 2.0

2.安装的步骤就不介绍了,下图是安装后的快捷方式,同时提供32位和64位两个版本,并有较为详细的帮助手册。

VMware PowerCLI

3.在运行VMware vSphere PowerCLI时要以管理员的方式运行,但PowerShell默认是禁止执行脚本,运行后如下图所示。

VMware PowerCLI1

可以运行set-executionpolicy Unrestricted命令,把当前的规则变成了不受限类型(从外部下载的任何脚本都可以运行,只不过运行前要发出一个警告)。

VMware PowerCLI2

然后退出,重新以管理员的方式运行。

4.用connect-viserver命令连接服务器后就可以运行PowerCLI命令或脚本了。

connect-viserver命令的语法:
    Connect-VIServer [[-Server] <String[]>] [-Port <Int32>] [-Protocol <String>] [-Credential<PSCredential>] [-User <String>] [-Password <String>] [-Session <String>] [-NotDefault] [-SaveCredentials] [<CommonParameters>]

    Connect-VIServer -Menu [<CommonParameters>]

具体信息可以运行get-help connect-viserver命令获得。

例如:

      ① connect-viserver -server 192.168.163.135 -user root -password Admin900

VMware PowerCLI3

   ② connect-viserver -server 192.168.163.135

 VMware PowerCLI4

5.相关下载

VMware vSphere 4.1 PowerCLI:

http://www.vmware.com/support/developer/PowerCLI/index.html

 

PowerShell 2.0默认包含在Windows 7和Windows Server 2008 R2中

下载Windows管理架构核心(WinRM 2.0和Windows PowerShell 2.0):

Windows Server 2008:

http://www.microsoft.com/downloads/details.aspx?FamilyId=863e7d01-fb1b-4d3e-b07d-766a0a2def0b

64位Windows Server 2008:

http://www.microsoft.com/downloads/details.aspx?FamilyId=d37e25cf-db05-4b23-a852-cdf865d81b82

Windows Server 2003:

http://www.microsoft.com/downloads/details.aspx?FamilyId=909bbcf1-bd78-4e03-8c83-69434717e551

Vista:

http://www.microsoft.com/downloads/details.aspx?FamilyId=f2fa1227-9a34-4e29-aa03-62f5c00e16f2

64位Vista:

http://www.microsoft.com/downloads/details.aspx?FamilyId=0f73efa2-f8d6-45f3-a8f8-5cdc205b119a

XP和Windows Embedded:

http://www.microsoft.com/downloads/details.aspx?FamilyId=60cb5b6c-6532-45e0-ab0f-a94ae9ababf5