vmware-powercli 用户命令管理手册

合集下载

PowerCLI命令使用方法

PowerCLI命令使用方法

PowerCLI使用方法1.通过Connect-VIServer 连接vCenter 或则主机例如:Connect-VIServer 192.168.1.20也可以同时连接多台机器例如:Connect-VIServer “192.168.1.11”, “192.168.1.12”2.连接服务器的时候会跳出对话框,需要输入用户名和密码。

输入用户和密码以后就可以连接到相应的服务器上。

3.如果每次都这样输入用户名和密码的话,对于管理员来说是比较麻烦的。

那可以通过命令来去记录用户名和密码,命令如下:$cred = Get-Credential在以上图片中出现的对话框里输入用户名和密码,就可以记录用户名和密码到文件中。

可以通过命令去查看记录的密钥信息:$Cred如下图:4.通过密钥文件进行连接服务器,命令如下:Connect-VIServer “192.168.1.11” , “192.168.1.12”–Credential $cred5.显示默认连接的服务器,命令如下:$global:DefaultVIServer6.在连接的服务器中有vCenter和主机,从连接的服务器中获得数据中心的信息;命令如下:Get-Datacenter7.通过命令来去获得数据中心虚拟机信息,命令如下:get-vm8.断开服务器的连接,命令如下:Disconnect-VIServer *命令分类1.显示清单和报告通过Get 命令来去获得结果例如:Get-VM;Get-Cluster2.部署与配置3.Maintenance and operations(维护与操作)4.Troubleshooting and Problem Resolution(问题解决)命令Demo1.显示VC的信息,命令如下:Cvi $vc2.显示所有命令的信息,命令如下Get-VICommand3.查某一个命令的信息的命令:Get-command *vmGet-VM 的使用1.Get-VM | set-vm –Description “this is a vm”2.获得集中一个虚拟机的具体信息命令:Get-vm 虚拟机名称| format-list3.可以通过设置命令来去简化查询:命令如下$vm = get-vm webCls命令清除界面的命令Get-Cluster Get-vmhost Get-vm的使用方式:通过get-cluster | get-vmhost 主机IP | get-vm 查看集中某一台主机的虚拟机的信息:通过命令导出虚拟机的信息数据,命令如下:Get-vm | Export-CSV –Path <filename.csv>通过命令调出Execl工具打开file.csv,命令如下Invoke-Item file.csv也可以通过命令导出虚拟机的某一些参数信息,如机器名,CPU个数,以及内存量,命令如下:通过命令查看虚拟机具体对象名称:CPU个数,内存,这些参数的指令名称,命令如下:Get-vm | Get-Member –MemberType property通过命令将虚拟机的信息导出为HTML的文档。

VMware脚本与命令管理手册

VMware脚本与命令管理手册

VMware脚本与命令(PowerCLI)管理手册VMware脚本与命令(PowerCLI)管理手册由于VMware是个成熟的虚拟化平台,所以它拥有几个自带的和第三方的管理选项。

图形用户界面GUI提供了直观的、概念上的管理VMware环境的方式,但这些对于大型或者重复的任务来说就略有不足。

如大量贮藏和虚拟机配置这些任务最好使用VMware脚本和命令套件。

在本期虚拟化技术手册中,我们将详细介绍VMware脚本和命令工具,如PowerShell与PowerCLI,以便有效监控VMware环境。

PowerCLI入门VMware管理任务是一项耗时和易出错的工作。

但是vSphere PowerCLI的扩展,可以帮助管理员完成一些控制工作。

本部分将探究VMware脚本工具PowerCLI的概念以及其中五个比较重要的脚本。

如何使用VMware vSphere PowerCLI?五大必备vSphere PowerCLI脚本PowerCLI使用与管理如果您刚刚开始应用PowerCLI管理VMware环境,需要学习的内容很多。

首先,最常见和最重要的cmdlets是Get-VM。

那么它该如何使用?如何设置能自动化主机服务器任务呢?要创建host profiles,PowerCLI能做些什么?这部分中,我们TecgTarget中国的特约作者Hal Rottenberg将详细介绍PowerCLI的使用与管理技巧。

掌控PowerCLI:使用Get-VM来管理虚拟机使用PowerShell与PowerCLI自动化主机服务器任务跳出框外巧解PowerShell与PowerCLI难题如何使用vSphere PowerCLI创建host profiles?在vSphere PowerCLI PowerShell界面使用host profilesPowerCLI技巧如何把VMware PowerCLI脚本功能应用到VMware SRM(Site Recovery Manager)恢复计划中?如何借助PowerCLI配置标准交换机?本部分将给出解决方法与步骤。

PowerCLI安装及使用

PowerCLI安装及使用

PowerCLI安装及使用vSphere PowerCLI试用(一):安装PowerCLIPowerCLI是VMware中的一款命令行管理工具。

一般管理VMware都使用vSphrere Client或者vSphere Web Client,vSphere PowerCLI则可以通过命令行来管理VMware vSphere主机或者是VMware vCenter。

(PowerCLI各版本下载,百度云、360云盘(提取码:46ab)),下载清单:1、VMware-PowerCLI-5.0.0-435426.exe2、VMware-PowerCLI-5.0.1-1992769.exe3、VMware-PowerCLI-5.1.0-793510.exe4、VMware-PowerCLI-5.1.0-1926866.exe5、VMware-PowerCLI-5.5.0-1295336.exe6、VMware-PowerCLI-5.5.0-1931983.exe7、VMware-PowerCLI-5.8.0-2057893.exe从官方主页上查看,目前的最新版本为5.8R1,下载VMware-PowerCLI-5.8.0-2057893.exe 后将其复制到需要安装的服务器上。

PowerCLI可以安装在vCenter上,也可以是其它服务器,这里选择第二种。

双击安装文件后开始安装,会先安装VIX和相关插件,如下图接着开始安装PowerCLI,如下图。

安装完成后,桌面上会多出两个图标,运行VMware vSphere PowerCLI在首次运行时可能会出错,如下图,使用get-executionpolicy查看状态确实为Restricted使用set-executionpolicy将属性从Restricted更改为remotesigned,如下图,完成后,将此窗口关闭再次启动后,就可以看到正常的界面了,如下图。

PowerCLI命令使用方法

PowerCLI命令使用方法

PowerCLI使用方法1.通过Connect-VIServer 连接vCenter 或则主机例如:Connect-VIServer 192.168.1.20也可以同时连接多台机器例如:Connect-VIServer “192.168.1.11”, “192.168.1.12”2.连接服务器的时候会跳出对话框,需要输入用户名和密码。

输入用户和密码以后就可以连接到相应的服务器上。

3.如果每次都这样输入用户名和密码的话,对于管理员来说是比较麻烦的。

那可以通过命令来去记录用户名和密码,命令如下:$cred = Get-Credential在以上图片中出现的对话框里输入用户名和密码,就可以记录用户名和密码到文件中。

可以通过命令去查看记录的密钥信息:$Cred如下图:4.通过密钥文件进行连接服务器,命令如下:Connect-VIServer “192.168.1.11” , “192.168.1.12”–Credential $cred5.显示默认连接的服务器,命令如下:$global:DefaultVIServer6.在连接的服务器中有vCenter和主机,从连接的服务器中获得数据中心的信息;命令如下:Get-Datacenter7.通过命令来去获得数据中心虚拟机信息,命令如下:get-vm8.断开服务器的连接,命令如下:Disconnect-VIServer *命令分类1.显示清单和报告通过Get 命令来去获得结果例如:Get-VM;Get-Cluster2.部署与配置3.Maintenance and operations(维护与操作)4.Troubleshooting and Problem Resolution(问题解决)命令Demo1.显示VC的信息,命令如下:Cvi $vc2.显示所有命令的信息,命令如下Get-VICommand3.查某一个命令的信息的命令:Get-command *vmGet-VM 的使用1.Get-VM | set-vm –Description “this is a vm”2.获得集中一个虚拟机的具体信息命令:Get-vm 虚拟机名称| format-list3.可以通过设置命令来去简化查询:命令如下$vm = get-vm webCls命令清除界面的命令Get-Cluster Get-vmhost Get-vm的使用方式:通过get-cluster | get-vmhost 主机IP | get-vm 查看集中某一台主机的虚拟机的信息:通过命令导出虚拟机的信息数据,命令如下:Get-vm | Export-CSV –Path <filename.csv>通过命令调出Execl工具打开file.csv,命令如下Invoke-Item file.csv也可以通过命令导出虚拟机的某一些参数信息,如机器名,CPU个数,以及内存量,命令如下:通过命令查看虚拟机具体对象名称:CPU个数,内存,这些参数的指令名称,命令如下:Get-vm | Get-Member –MemberType property通过命令将虚拟机的信息导出为HTML的文档。

vmware命令行

vmware命令行

vmware命令⾏VMware vSphere PowerCLI 是⼀款功能强⼤的命令⾏⼯具,可⾃动执⾏ vSphere 的各⽅⾯管理,包括主机、⽹络、存储、虚拟机、客户操作系统等等打开打开的⽅法第⼀种1.直接在ESXi控制台界⾯上按住ALT+F1也能进⼊2.把ESXi的SSH功能开开,然后⽤⼯具连接⾏了,root/password。

选择esxi主机----配置--(软件)安全配置-----(安全配置⽂件)属性---(ssh)选项打开后远程root 密码链接即可。

常⽤命令主机信息查询vmware -v 查询系统版本esxcli system version get 查询系统信息esxcli system time get 查询时间esxcli system time set -y=2016 -M=9 -d=13 -H=10 -m=9esxcli system maintenanceMode set --enable true/false 进⼊/退出维护模式esxcli system maintenanceMode get 查询维护模式esxcli system shutdown reboot/poweroff 关机/重启/断电⽹络信息查询esxcli network ip interface ipv4 get 查询ipesxcli network ip route ipv4 list 查询路由表esxcli network nic list 查询⽹卡 up/down 信息esxcli network nic down/up -n=vmnic1 关闭/打开⼀个⽹卡 -n=指定⽹卡磁盘信息esxcli storage core device list 查看磁盘列表利⽤vshpere powercli 管理vcenter安装powe rcli ( windows)安装过程:1、下载VMWare.PowerCLI Save-Module -Name VMware.PowerCLI #执⾏后,会提⽰要输⼊path,它的⽬的是询问你将powercli软件下载到哪2、安装install-module VMware.PowerCLI3、导⼊模块Import-Module VMware.VimAutomation.Core4 设置powercli的证书机制为ignore。

【转】VMwareCLI命令参考

【转】VMwareCLI命令参考

【转】VMwareCLI命令参考VMwareCLI命令参考基本命令范例123 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41vmware -v# 看你的esx版本VMware ESXi 5.0.0 build-469512esxcfg-info -a # 显⽰所有ESX相关信息esxcfg-info -w # 显⽰esx上硬件信息service mgmt-vmware restart # 重新启动vmware服务esxcfg-vmknic -l # 查看宿主机IP地址esxcli hardware cpu list # cpu信息 Brand,Core Speed,esxcli hardware cpu global get # cpu信息(CPU Cores)esxcli hardware memory get # 内存信息内存 Physical Memoryesxcli hardware platform get # 硬件型号,供应商等信息,主机型号,Product Name 供应商,Vendor Nameesxcli hardware clock get # 当前时间esxcli system version get # 查看ESXi主机版本号和build号esxcli system maintenanceMode set--enable yes# 将ESXi主机进⼊到维护模式esxcli system maintenanceMode set--enable no # 将ESXi主机退出维护模式esxcli system settings advanced list -d # 列出ESXi主机上被改动过的⾼级设定选项esxcli system settings kernel list -d # 列出ESXi主机上被变动过的kernel设定部分esxcli system snmp get | hash| set| test# 列出、测试和更改SNMP设定esxcli vm process list # 利⽤esxcli列出ESXi服务器上VMs的World I(运⾏状态的)esxcli vm process kill-t soft -w WorldI # 利⽤esxcli命令杀掉VMvim-cmd hostsvc/hostsummary# 查看宿主机摘要信息vim-cmd vmsvc/get.datastores # 查看宿主存储空间信息vim-cmd vmsvc/getallvms# 列出所有虚拟机vim-cmd vmsvc/power.getstate VMI # 查看指定VMI虚拟状态vim-cmd vmsvc/power.shutdown VMI # 关闭虚拟机vim-cmd vmsvc/power.off VMI # 如果虚拟机没有关闭,使⽤poweroff命令vim-cmd vmsvc/get.config VMI # 查看虚拟机配置信息esxcli software vib install-d /vmfs/volumes/datastore/patches/xxx.zip # 为ESXi主机安装更新补丁和驱动esxcli network nic list # 列出当前ESXi主机上所有NICs的状态esxcli network vm list # 列出虚拟机的⽹路信息esxcli storage nmp device list # 理出当前NMP管理下的设备satp和psp信息esxcli storage core device vaai status get # 列出注册到PS设备的VI状态esxcli storage nmp satp set--default-psp VMW_PSP_RR --satp xxxx # 利⽤esxcli命令将缺省psp改成Round Robinesxcli信息查询esxcli命令帮助信息ssh登录VMware ESX server控制台,⽤esxcli命令查询虚拟机信息,输出格式⽀持普通、xml、csv、keyvalue。

PowerVM常用命令手册

PowerVM常用命令手册

PowerVM常用命令手册目录目录 (1)1. 基本操作 (3)2. 创建VIOS分区 (3)3. VIOS配置 (7)3.1 创建共享以太网卡SEA(Shared Ethernet Adapter) (7)3.2 创建VSCSI虚拟磁盘 (7)3.3 NPIV配置 (12)3.4 参数调整 (16)3.5 VIO测试 (18)3.6 设置VIO Server分区自动启动 (19)4. VIOS巡检工作 (21)5. 虚拟资源的调整 (22)6. VIOS、VIOC配置实例 (25)7. WPAR技术 (32)7.1 创建Application WPAR (33)7.2 创建System WPAR (34)7.3 如何确定当前是在Global Environment中还是在WPAR中 (36)7.4如何关闭WPAR (36)7.5 如何重启WPAR (37)7.6修改WPAR的名字 (39)7.7 WPAR的状态 (39)7.8 删除WPAR (40)7.9 WPAR中的文件系统管理 (41)7.10 同步WPAR配置 (45)7.11备份、恢复、克隆WPAR (45)7.12 WPAR用户和组管理 (46)7.13 恢复WPAR中的用户口令 (46)7.14修改MPIO磁盘的hcheck_interval属性 (47)8. 存在多个VLAN ID的TCP/IP网络 (47)9. Active Memory Expansion(AME)技术 (50)10. 备份和恢复VIO Server (53)10.1 备份VIO Server (53)10.2 恢复VIO Server (55)11. 故障处理 (56)11.1 收集虚拟资源配置信息 (56)11.2更换VIO Server的SEA物理网卡 (56)12. topas性能监控 (58)1. 基本操作默认用户:padmin默认无密码默认用户环境为受限的Korn Shell切换到AIX root用户环境命令:oem_setup_env安装VIOS系统installios接受VIOS License文件命令:license -accept升级VIOS版本命令:updateios -commitupdateios -accept -install -dev /dev/cd0ioslevelshutdown -restart备份VIOS的配置:viosbr -backup -file /home/padmin/<backupfile_name>恢复VIOS的配置:viosbr -restore -file <backupfile_name>.tar.gz备份VIOS系统backupiosroot用户环境下输入VIOS配置命令:/usr/ios/cli/ioscli lsmap -all查看分区的CPU、内存配置lparstat -i2. 创建VIOS分区一个shared、uncapped Processor分区作为VIOS分区即可,在同一台服务器上可以部署多个VIOS分区,例如在网络IO和磁盘IO都很繁忙的应用环境,可以部署四个VIOS分区,其中两个VIOS负责处理Virtual Ethernet,另外两个VIOS负责处理Virtual Disk。

VMWare虚拟化管理员平台管理手册

VMWare虚拟化管理员平台管理手册

VMWare虚拟化管理员平台管理手册目录1管理平台登录介绍 (3)1.1管理平台客户端登陆 (3)2创建虚拟机模板 (7)2.1新建虚拟机 (7)2.2虚拟机创建完毕后为虚拟机安装操作系统。

(19)2.3优化模板 (39)2.4XP系统的优化 (68)2.5优化工具优化 (79)2.6语音室管理员需要执行的特殊操作 (79)2.7执行快照 (84)2.8生成模板 (86)3发布虚拟机 (92)3.1发布虚拟机 (92)3.2重构和刷新虚拟机 (112)4管理员部分安装文件获取和系统登陆 (118)1管理平台登录介绍1.1 管理平台客户端登陆1、下载管理客户端vsphere client使用网页输入以下地址:https://如下图1所示点击“继续访问”。

注:如果本地计算机【指您现在操作的计算机,以下称本地计算机】。

图1登陆结果为:图2 ,点击图中的下载vsphere client ,即可下载您想要的客户端。

图2选择您需要保存的路径,此处不同的下载工具设置保存路径的方法不同,此处视自己的情况而定。

图3下载完成后如图4 ,双击运行安装。

图4安装完成后的如图:双击运行2、登陆平台及管理以下是实训室管理员拥有的账户:sxsadmin 、sxsadmin2 、sxsadmin3 ,密码为admin2014 Ip地址或者名称栏内填写vcenter的名称:或者ip地址:10.0.7.123弹出证书问题时点击安装证书并忽略。

实训室的管理员账户登陆后所见的管理控制台的界面如图,只显示了超级管理员授权的桌面资源池等。

在该资源池中,管理员具有全部的权限,包括创建虚拟机等。

切换到虚拟机和模板视图:图中的管理员只能看见授权的教室的文件夹的内容。

在该文件夹下具有管理员的权限。

切换视图为存储和网络视图:管理员只能看见shixun4的存储,并且只有简单的文件处理及浏览分配空间的权限。

网络的视图中:管理员只能看见属于自己授权范围内的网络,并且不能更改,只能使用。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VMware PowerCLI User's GuideVMware PowerCLI 6.5.4VMware PowerCLI User's GuideYou can find the most up-to-date technical documentation on the VMware website at:https:///If you have comments about this documentation, submit your feedback todocfeedback@VMware, Inc.3401 Hillview Ave.Palo Alto, CA 94304Copyright © 1998–2017 VMware, Inc. All rights reserved. Copyright and trademark information.ContentsVMware PowerCLI User's Guide81Introduction to VMware PowerCLI9Microsoft PowerShell Basics9PowerShell Command-Line Syntax10PowerShell Pipelines10PowerShell Wildcards10PowerShell Common Parameters10PowerCLI Concepts11PowerCLI Modules12Interoperability Between the PowerCLI and vCloud Director PowerCLI Modules13Selecting Objects in PowerCLI14Providing Login Credentials15Running PowerCLI Cmdlets Asynchronously15Managing Default Server Connections16Customization Specification Objects in PowerCLI16Using ESXCLI with PowerCLI16PowerCLI Inventory Provider17PowerCLI Datastore Provider17PowerCLI About Articles172Installing VMware PowerCLI19Supported Operating Systems20Supported VMware Products20Supported Windows PowerShell Versions20Prerequisites for Installing and Running PowerCLI20Install PowerCLI20Allow Execution of Local Scripts21Update a PowerCLI Module21Uninstall PowerCLI223Configuring VMware PowerCLI23Scoped Settings of PowerCLI23Configuring the Scope of the PowerCLI Settings23Priority of Settings Scopes in PowerCLI24PowerCLI Configuration Files24Using Custom Scripts to Extend the Operating System Support for PowerCLI Cmdlets254Configuring Customer Experience Improvement Program26Categories of Information That VMware Receives26Join the Customer Experience Improvement Program in PowerCLI265Sample Scripts for Managing vSphere with VMware PowerCLI27 Connect to a vCenter Server System31Manage Virtual Machines on vSphere32Add a Standalone Host to a vCenter Server System33Set the License Key for a Host on vCenter Server33Activate Maintenance Mode for a Host on vCenter Server34Create vSphere Inventory Objects34Create Virtual Machines on vCenter Server Using an XML Specification File36Manage Virtual Machine Templates on vCenter Server36Create and Use Snapshots on vCenter Server37Update the Resource Configuration Settings of a Virtual Machine on vCenter Server38Get a List of Hosts on a vCenter Server System and View Their Properties38Change the Host Advanced Configuration Settings on vCenter Server39Move a Virtual Machine to a Different Host Using VMware vSphere vMotion40Move a Virtual Machine to a Different Datastore Using VMware vSphere Storage vMotion40 Create a Host Profile on a vCenter Server System41Apply a Host Profile to a Host on vCenter Server41Manage Statistics and Statistics Intervals on vCenter Server42Modify the Settings of the NIC Teaming Policy for a Virtual Switch43Create a vApp on vCenter Server43Modify the Properties of a vApp44Export or Import vApps44Create an iSCSI Host Storage45Add Passthrough Devices to a Host and Virtual Machine45Create a Custom Property Based on an Extension Data Property46Create a Script-Based Custom Property for a vSphere Object46Apply a Customization Object to a Cloned Virtual Machine47Modify the Default NIC Mapping Object of a Customization Specification48Modify Multiple NIC Mapping Objects of a Customization Specification48Create Multiple Virtual Machines that Use Static IP Addresses49Create Multiple Virtual Machines with Two Network Adapters51Create a vSphere Role and Assign Permissions to a User52View the Action Triggers for an Alarm on vCenter Server53Create and Modify Alarm Actions and Alarm Triggers on vCenter Server53Remove Alarm Actions and Triggers54Create and Modify Advanced Settings for a Cluster55Modify the vCenter Server Email Configuration55Modify the vCenter Server SNMP Configuration56Use Esxtop to Get Information on the Virtual CPUs of a Virtual Machine56Filter vSphere Objects with Get-View57Populate a View Object with Get-View58Update the State of a Server-Side Object58Reboot a Host with Get-View59Modify the CPU Levels of a Virtual Machine with Get–View and Get–VIObjectByVIView60 Browse the Default Inventory Drive60Create a New Custom Inventory Drive61Manage Inventory Objects Through Inventory Drives61Browse the Default Datastore Drives62Create a New Custom Datastore Drive63Manage Datastores Through Datastore Drives63Modify the Timeout Setting for Web Tasks64Using Tags65Retrieve a Tag and Save It into a Variable65Retrieve a Tag Category and Save It into a Variable66Create a Tag Category and a Tag66Assign a Tag to Virtual Machines66Retrieve Objects by Tag67Generate Tags Automatically by Using a Script67Add an Entity Type to a Tag Category68Retrieve Tag Assignments68Network Management with vSphere Distributed Switches69Create a Distributed Switch and Configure Networking69Configure a Distributed Switch70Migrate Virtual Machine Networking Configuration from a vSphere Standard Switch to a vSphere Distributed Switch70Migrate Physical and Virtual NICs to a vSphere Standard Switch71Migrate Physical and Virtual NICs to a vSphere Distributed Switch72Configure the Traffic Shaping Policy73Configure the Security Policy73Create a Virtual Machine from a Content Library Item73Create a vApp from a Content Library Item74Create a New VM-VM DRS Rule74Create a New VM-VMHost DRS Rule756Sample Scripts for Managing vSphere Policy-Based Storage with VMware PowerCLI77Create a Tag-Based Storage Policy77Create a Capability-Based Storage Policy78Associate a Storage Policy with a Virtual Machine and Its Hard Disk79Disassociate a Storage Policy Associated with a Virtual Machine and Its Hard Disk80Enable SPBM on a Cluster and Verify that It Is Enabled80Remove a Storage Policy81Edit a Storage Policy81Export and Import a Storage Policy82Create a Virtual Machine in a Datastore Compatible with Storage Policy82Create a vSAN Datastore84Modify a vSAN Datastore85Create a vSAN Stretched Cluster86Create an NFS 4.1 Datastore87Add a VASA Provider and Create a Policy88Invoke a Planned Failover on a Replication Group and Reverse the Replication90Attach a Flat VDisk to a Virtual Machine927Sample Scripts for Managing VMware Site Recovery Manager with VMware PowerCLI93Connect to an SRM Server93Protect a Virtual Machine94Create a Report of the Protected Virtual Machines94Create a Report of the Virtual Machines Associated with All Protection Groups958Sample Scripts for Managing the vSphere Automation SDK withVMware PowerCLI97Create a Local Content Library on an Existing Datastore979Sample Scripts for Managing vCloud Director with VMware PowerCLI99 Connect to a vCloud Director Server100Create and Manage Organizations101Create and Manage Organization Virtual Data Centers101Filter and Retrieve Organization Virtual Data Center Networks102Import a vApp Template from the Local Storage103Create a vApp Template from a vApp103Import a vApp from vSphere104Create and Modify a vApp105Manage Virtual Machines with vApps105Manage Virtual Machines and Their Guest Operating Systems106Retrieve a List of the Internal and External IP Addresses of Virtual Machines in vApps107 Create and Manage Access Control Rules108Filter and Retrieve vApp Networks108Create vApp Networks for a Selected vApp109Create an Isolated vApp Network109Create an NAT Routed vApp Network110Create a Direct vApp Network110Modify or Remove vApp Networks11110Sample Scripts for Managing vCloud Air with VMware PowerCLI113 Connect to a vCloud Air Server113Retrieve vApps from a Data Center114Retrieve vApps from a Compute Instance114Running vCloud Director Scripts Against vCloud Air11511Sample Scripts for Managing vSphere Update Manager with VMware PowerCLI116Connect to a vCenter Server System116Create Patch Baselines117Attach and Detach Baselines118Scan a Virtual Machine118Check Virtual Machine Baseline Status119Stage Patches119Remediate a Virtual Machine120Upgrade Virtual Machine Hardware120Remediate a Cluster120Remediate a Host121Download Patches and Scan Objects12112Sample Scripts for Managing vRealize Operations Manager with VMware PowerCLI123Connect to a vRealize Operations Manager Server123Check Memory Waste Levels124Get Remediation Recommendations124Change Alert Ownership125Create a Report for Problematic Hosts125VMware PowerCLI User's GuideThe VMware PowerCLI User's Guide provides information about installing and using theVMware PowerCLI cmdlets (pronounced “commandlets”) for managing, monitoring, automating, and handling operations for VMware® vSphere, VMware Site Recovery Manager, vSphere Automation SDK, vCloud Director, vCloud Air, vSphere Update Manager, vRealize Operations Manager, VMware Horizon, NSX-T, and VMware Cloud on AWS components.To help you start with PowerCLI, this documentation includes descriptions of specific PowerCLI concepts and features. In addition, this documentation provides a set of use case examples and sample scripts.Intended AudienceThis guide is intended for anyone who wants to install and use PowerCLI. This documentation is written for administrators and developers who are familiar with virtual machine technology and Windows PowerShell.n Basic administrators can use cmdlets included in PowerCLI to manage their vSphere, VMware Site Recovery Manager, vSphere Automation SDK, vCloud Director, vCloud Air,vSphere Update Manager, vRealize Operations Manager, VMware Horizon, NSX-T, andVMware Cloud on AWS infrastructure from the command line.n Advanced administrators can develop PowerShell scripts that other administrators can reuse or integrate into other applications.Introduction toVMware PowerCLI1VMware PowerCLI contains modules of cmdlets based on Microsoft PowerShell for automating vSphere, VMware Site Recovery Manager, vSphere Automation SDK, vCloud Director, vCloud Air,vSphere Update Manager, vRealize Operations Manager, VMware Horizon, NSX-T, andVMware Cloud on AWS administration. VMware PowerCLI provides a PowerShell interface to the VMware product APIs.n Microsoft PowerShell BasicsPowerCLI is based on Microsoft PowerShell and uses the PowerShell basic syntax and concepts.n PowerCLI ConceptsPowerCLI cmdlets are created to automate VMware environments administration and to introduce some specific features in addition to the PowerShell concepts.Microsoft PowerShell BasicsPowerCLI is based on Microsoft PowerShell and uses the PowerShell basic syntax and concepts. Microsoft PowerShell is both a command-line and scripting environment, designed for Windows. It uses the .NET object model and provides administrators with system administration and automation capabilities. To work with PowerShell, you run commands, named cmdlets.n PowerShell Command-Line SyntaxPowerShell cmdlets use a consistent verb-noun structure, where the verb represents the action and the noun represents the object to operate on.n PowerShell PipelinesA pipeline is a series of commands separated by the pipe operator |.n PowerShell WildcardsPowerShell has a number of pattern-matching operators named wildcards that you can use tosubstitute one or more characters in a string, or substitute the complete string.n PowerShell Common ParametersThe Windows PowerShell engine retains a set of parameter names, referred to as commonparameters. All PowerShell cmdlets, including the PowerCLI cmdlets, support them.VMware PowerCLI User's GuidePowerShell Command-Line SyntaxPowerShell cmdlets use a consistent verb-noun structure, where the verb represents the action and the noun represents the object to operate on.PowerShell cmdlets follow consistent naming patterns, ensuring that construction of a command is easy if you know the object that you want to work with.All command categories take parameters and arguments. A parameter starts with a hyphen and is used to control the behavior of the command. An argument is a data value consumed by the command.A simple PowerShell command has the following syntax:command -parameter1 -parameter2 argument1, argument2PowerShell PipelinesA pipeline is a series of commands separated by the pipe operator |.Each command in the pipeline receives an object from the previous command, performs some operation on it, and then passes it to the next command in the pipeline. Objects are output from the pipeline as soon as they become available.PowerShell WildcardsPowerShell has a number of pattern-matching operators named wildcards that you can use to substitute one or more characters in a string, or substitute the complete string.All wildcard expressions can be used with the PowerCLI cmdlets. For example, you can view a list of all files with a .txt extension by running dir *.txt. In this case, the asterisk * operator matches any combination of characters.With wildcard patterns you can indicate character ranges as well. For example, to view all files that start with the letter S or T and have a .txt extension, you can run dir [st]*.txt.You can use the question mark ? wildcard to match any single character within a sequence of characters. For example, to view all .txt files with names that consist of string and one more character at the end, run dir string?.txt.PowerShell Common ParametersThe Windows PowerShell engine retains a set of parameter names, referred to as common parameters. All PowerShell cmdlets, including the PowerCLI cmdlets, support them.Some of the PowerShell common parameters are Verbose, Debug, ErrorAction, ErrorVariable, OutVariable, and OutBuffer. For a full list of the common parameters and more details on their usage, run Get-Help about_CommonParameters.PowerShell offers two risk mitigation parameters: WhatIf and Confirm.WhatIf Displays the effects of a command without running it.Confirm Prompts for confirmation before running a command that stops a programor service, or deletes data.PowerCLI ConceptsPowerCLI cmdlets are created to automate VMware environments administration and to introduce some specific features in addition to the PowerShell concepts.n PowerCLI ModulesVMware PowerCLI 6.5.4 consists of multiple modules that you can install and use according to your needs and environments.n Interoperability Between the PowerCLI and vCloud Director PowerCLI Modules With the RelatedObject parameter of PowerCLI cmdlets, you can retrieve vSphere inventory objects from cloud resources. This interoperability between the PowerCLI andvCloud Director PowerCLI modules expands cloud administration, automation, reporting, andtroubleshooting options for provider administrators.n Selecting Objects in PowerCLIIn PowerCLI, you can pass strings and wildcards to all parameters that take inventory objects,datastores, OSCustomizationSpec objects, and VIServer objects as arguments. This PowerCLI approach is named Object-by-Name (OBN) selection.n Providing Login CredentialsWhen you provide login credentials in the command prompt or in a script file, a PowerShell limitation might prevent PowerCLI from processing non-alphanumeric characters correctly. To prevent login problems, escape the non-alphanumeric characters in your credentials.n Running PowerCLI Cmdlets AsynchronouslyBy default, PowerCLI cmdlets return an output only after completion of the requested tasks. If you want a cmdlet to return to the command line immediately, without waiting for the tasks to complete, you can use the RunAsync parameter.n Managing Default Server ConnectionsBy default, PowerCLI and PowerCLI cmdlets run on the vCenter Server systems or vCloud Director servers you are connected to, if no target servers can be determined from the provided parameters.n Customization Specification Objects in PowerCLIPowerCLI provides two types of objects for customization specification: persistent andnonpersistent.n Using ESXCLI with PowerCLIPowerCLI provides you the capability to use ESXCLI through its console.n PowerCLI Inventory ProviderThe Inventory Provider is designed to expose an unfiltered inventory view of the inventory items from a server.n PowerCLI Datastore ProviderThe Datastore Provider is designed to provide access to the contents of one or more datastores.n PowerCLI About ArticlesYou can learn more about some PowerCLI concepts and features from the built-in help articlesnamed about articles. You can access them through a running PowerCLI process.PowerCLI ModulesVMware PowerCLI 6.5.4 consists of multiple modules that you can install and use according to your needs and environments.The following table lists all official VMware PowerCLI modules.VMware.PowerCLI Provides a root module which other modules are dependent on.This module ensures the PowerCLI product can be installed,upgraded, and removed as a complete package if needed.VMware.VimAutomation.Core Provides cmdlets for automated administration of the vSphereenvironment.mon Provides functionality that is common to all PowerCLI modules.This module has no cmdlets, but is required for other modules tofunction correctly.VMware.VimAutomation.Sdk Provides SDK functionality that is needed by all PowerCLImodules. This module has no cmdlets, but is required for othermodules to function correctly.VMware.VimAutomation.Vds Provides cmdlets for managing vSphere distributed switchesand distributed port groups.VMware.VimAutomation.Cis.Core Provides cmdlets for managing vSphere Automation SDKservers.VMware.VimAutomation.Storage Provides cmdlets for managing vSphere policy-based storage. VMware.VimAutomation.StorageUtility Provides utility scripts for storage.VMware.VimAutomation.HA Provides the Get-DrmInfo cmdlet for managing High Availabilityfunctionality.VMware.VimAutomation.License Provides the Get-LicenseDataManager cmdlet for managingVMware License components.VMware.ImageBuilder Provides cmdlets for managing depots, image profiles, andVIBs.VMware.DeployAutomation Provides cmdlets that provide an interface to VMware AutoDeploy for provisioning physical hosts with ESXi software. VMware.VimAutomation.Cloud Provides cmdlets for automating vCloud Director features.VMware.VimAutomation.PCloud Provides cmdlets for automating vCloud Air features.VMware.VumAutomation Provides cmdlets for automating vSphere Update Managerfeatures.VMware.VimAutomation.vROps Provides cmdlets for automating vRealize Operations Managerfeatures.VMware.VimAutomation.Srm Provides cmdlets for managing VMware Site Recovery Managerfeatures.VMware.VimAutomation.HorizonView Provides cmdlets for automating VMware Horizon features. VMware.VimAutomation.Nsxt Provides cmdlets for managing NSX-T servers.VMware.VimAutomation.Vmc Provides cmdlets for automating VMware Cloud on AWSfeatures.Interoperability Between the PowerCLI andvCloud Director PowerCLI ModulesWith the RelatedObject parameter of PowerCLI cmdlets, you can retrieve vSphere inventory objects from cloud resources. This interoperability between the PowerCLI and vCloud Director PowerCLI modules expands cloud administration, automation, reporting, and troubleshooting options for provider administrators.Note To use the interoperability feature, you must install the PowerCLI and vCloud Director PowerCLI modules, and connect both to a vCloud Director server and a vCenter Server system.Retrieving vSphere Inventory Objects from Cloud ResourcesProvider administrators can use the RelatedObject parameter of PowerCLI cmdlets to retrieve vSphere inventory objects from vCloud Director objects. Passing the retrieved objects to the cmdlets of the VMware.VimAutomation.Core and VMware.VimAutomation.VDS modules, extends administration options.Important Use of the VMware.VimAutomation.Core and VMware.VimAutomation.VDS modules to modify the configuration of objects that are managed by vCloud Director might result in unpredictable behavior of the cloud environment.Table 1‑1. List of Supported vSphere Inventory Objects You Can Retrieve from Cloud ObjectsTable 1‑1. List of Supported vSphere Inventory Objects You Can Retrieve from Cloud Objects (Continued)ExternalNetwork VDPortgroupGet-ExternalNetwork -Name'MyExternalNetwork' | Get-VDPortGroupSelecting Objects in PowerCLIIn PowerCLI, you can pass strings and wildcards to all parameters that take inventory objects, datastores, OSCustomizationSpec objects, and VIServer objects as arguments. This PowerCLI approach is named Object-by-Name (OBN) selection.Instead of assigning an object name to a cmdlet parameter, users can pass the object through a pipeline or a variable. For example, the following three commands are interchangeable:n Remove-VM -VM "Win 7 SP1"n Get-VM -Name "Win 7 SP1" | Remove-VMn Remove-VM -VM (Get-VM -Name "Win 7 SP1")Note In PowerCLI, passing strings as pipeline input is not supported.If you provide a non-existing object name, an OBN failure occurs. In such cases, PowerCLI generates a non-terminating error and runs the cmdlet ignoring the invalid name.For more details about OBN, run help about_OBN.Example: An OBN failureThis example illustrates the occurrence of an OBN failure.Set-VM –VM “VM1”, “VM2”, “VM3” –Server $server1, $server2 –MemoryGB 4If the VM2 virtual machine does not exist on either of the selected servers, PowerCLI generates a non-terminating error and applies the command only on the VM1 and VM3 virtual machines.Providing Login CredentialsWhen you provide login credentials in the command prompt or in a script file, a PowerShell limitation might prevent PowerCLI from processing non-alphanumeric characters correctly. To prevent login problems, escape the non-alphanumeric characters in your credentials.To escape non-alphanumeric characters in PowerCLI, you need to place the expression that contains them in single quotes (').Note When you provide your login credentials in the Specify Credential dialog box, you do not need to escape non-alphanumeric characters.Example: Connecting to a vCenter Server SystemThis example illustrates how to escape non-alphanumeric characters when connecting to a selected vCenter Server instance with the Adminis!ra!or user name and the pa$$word password.Connect-VIServer -Server 10.23.112.235 -Protocol https -Username 'Adminis!ra!or' -Password 'pa$$word'Running PowerCLI Cmdlets AsynchronouslyBy default, PowerCLI cmdlets return an output only after completion of the requested tasks. If you want a cmdlet to return to the command line immediately, without waiting for the tasks to complete, you can use the RunAsync parameter.When you use the RunAsync parameter, the cmdlet returns Task objects instead of its usual output. The Status property of a returned Task object contains a snapshot of the initial state of the task. This state is not updated automatically and has the values Error, Queued, Running, or Success. You can refresh a task state by retrieving the task object with the Get-Task cmdlet. If you want to observe the progress of a running task and wait for its completion before running other commands, use the Wait-Task cmdlet.Note In PowerCLI, the RunAsync parameter affects only the invocation of a cmdlet and does not control whether the initiated tasks run consecutively or in parallel. For example, the Remove-VM cmdlet might remove the selected virtual machines simultaneously or consecutively depending on the internal design of PowerCLI. To make sure that tasks initiated by a cmdlet run consecutively, run the cmdlet in a loop, each time applying it to a single object.Example: Running Remove-VM with and without the RunAsync parameter Remove-VM $vmListThe command returns no output when all virtual machines stored in the $vmList variable are removed, irrespective of whether they are removed simultaneously.Remove-VM $vmList -RunAsyncThe command returns an output that consists of one or more Task objects immediately.Managing Default Server ConnectionsBy default, PowerCLI and PowerCLI cmdlets run on the vCenter Server systems or vCloud Director servers you are connected to, if no target servers can be determined from the provided parameters.When you connect to a vCenter Server system by using Connect-VIServer, the server connection is stored in the $DefaultVIServers array variable. This variable contains all connected servers for the current PowerCLI session. To remove a server from the $DefaultVIServers variable, you can either use Disconnect-VIServer to close all active connections to this server, or modify the value of $DefaultVIServers manually.When you connect to a vCloud Director system by using Connect-CIServer, the server connection is stored in the $DefaultCIServers array variable. This variable contains all connected servers for the current session. To remove a server from the $DefaultCIServers variable, you can either use Disconnect-CIServer to close all active connections to this server, or modify the value of $DefaultCIServers manually.Customization Specification Objects in PowerCLIPowerCLI provides two types of objects for customization specification: persistent and nonpersistent.Persistent CustomizationPersistent customization specification objects are stored on the vSphere server. All persistent customization specifications created by using vSphere Client or VMware PowerCLI 4.1 or later are encrypted. Encrypted customization specifications can be applied only by the server that has encrypted them.Nonpersistent CustomizationNonpersistent customization specification objects exist only inside the current PowerShell process. Nonpersistent customization specification objects are not encrypted, but cloning them to a vSphere server encrypts them.Using ESXCLI with PowerCLIPowerCLI provides you the capability to use ESXCLI through its console.PowerCLI provides two approaches for working with ESXCLI:n Through the Get-ESXCli cmdlet, which provides direct access to the ESXCLI namespaces, applications, and commands.n Through .NET methods, which you use to create managed objects that correspond to specific ESXCLI applications. To access the ESXCLI, you can call methods on these managed objects.Note To call a method of an ESXCLI object, you must provide values for all parameters. If you want to omit a given parameter, pass $null as its argument.PowerCLI Inventory ProviderThe Inventory Provider is designed to expose an unfiltered inventory view of the inventory items from a server.It enables navigation and file-style management of the VMware vSphere inventory. By creating a PowerShell drive based on a managed object (such as a data center), you can obtain a view of its contents and the relationships between the items. In addition, you can move, rename, or delete objects by running commands from the PowerShell console.When you connect to a server with Connect-VIServer, the cmdlet builds two default inventory drives: vi and vis. The vi inventory drive shows the inventory on the last connected server. The vis drive contains the inventory of all vSphere servers connected within the current PowerCLI session.You can use the default inventory drives or create custom drives based on the default ones.PowerCLI Datastore ProviderThe Datastore Provider is designed to provide access to the contents of one or more datastores.The items in a datastore are files that contain configuration, virtual disk, and the other data associated with a virtual machine.When you connect to a server with Connect-VIServer, the cmdlet builds two default datastore drives: vmstore and vmstores. The vmstore drive provides a list of the datastores available on the vSphere server that you last connected to.Note If you establish multiple connections to the same vSphere server, the vmstore drive is not updated.The vmstores drive contains all datastores available on all vSphere servers that you connected to within the current PowerCLI session.You can use the default datastore drives or create custom drives based on the default ones.PowerCLI About ArticlesYou can learn more about some PowerCLI concepts and features from the built-in help articles named about articles. You can access them through a running PowerCLI process.Running Help About_* lists all built-in Windows PowerShell and VMware PowerCLI about articles.。

相关文档
最新文档