# VMware PowerCLI
> [!question]- PowerCLI 是 VMware 基于 PowerShell 的自动化和配置管理工具
> - 能够以 Shell 和脚本方式实现 vSphere Client 等界面大部分任务和操作
## 1 部署 PowerCLI
- 系统要求 [[vsv-console|>>]]
- .NET Framework 4.7.2+
- Windows PowerShell 5.1
- 互操作性 [>>](https://interopmatrix.vmware.com/Interoperability?col=299,&row=0,)
- 下载 (离线安装)
- 模块文件 VMware-PowerCLI-13.2.1-22851661.zip [>>](https://developer.vmware.com/web/tool/vmware-powercli/)
- 示例脚本 PowerCLI-Example-Scripts-master.zip [>>](https://github.com/vmware/PowerCLI-Example-Scripts)
- 准备
- 检查 PowerShell 版本, 模块路径 - `$PSVersionTable.PSVersion`, `$Env:PSModulePath`
- (如有) 检查已安装 PowerCLI 模块版本 - `Get-Module VMware* -ListAvailable`
- 如需升级, 移除模块路径下现有 PowerCLI 模块目录后重新安装
### 1.1 安装 (离线)
1. 解压 ZIP, 拷贝内容到 PowerShell 模块路径, 如`"C:\Program Files\WindowsPowerShell\Modules"`
2. 解除文件锁定 `Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules' -Recurse | Unblock-File`
3. 验证 `Get-Module VMware* -ListAvailable`
### 1.2 设置
- 忽略证书警告 `Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false`
- 关闭 CEIP `Set-PowerCLIConfiguration -ParticipateInCEIP $false -Confirm:$false`
- 临时修改 PowerShell 执行政策 `Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force` [>>](https://learn.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4)
- `Unrestricted` - 允许任何脚本执行
- 检查当前执行策略 `Get-ExecutionPolicy`
- 切回 Windows Server 默认执行策略 `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force`
- 切回 Windows 10 / 11 默认执行策略 `Set-ExecutionPolicy -ExecutionPolicy Restricted -Force`
### 1.3 验证
- 连接 vCenter Server - `Connect-VIServer`
- 连接 Horizon 连接服务器 - `Connect-HVServer`
- 连接 NSX-T Manager - `Connect-NsxtServer`
## 2 使用 PowerCLI
#VSV-PowerCLI-snippets
---
> [!info] 本页面永久链接 https://fillgaps.pro/vsv-references/vsv-tools/powercli
> [!info] 本页面最新 [PDF](https://file.fillgaps.pro/powercli_2404v1.pdf) 和 [Web](https://file.fillgaps.pro/powercli_2404v1.mht) 下载
> [!info] 本页面如有纠正或补充建议, 请发[邮件](mailto:
[email protected])或公众号私信
---
## 3 参考资源
- VMware 知识库 [[vsv-kb-contents|>>]]
- [Using the vSphere PowerCLI utility to manage your vSphere environment (2032946)](https://knowledge.broadcom.com/external/article?legacyId=2032946)
- VMware 技术资源 [[vsv-tec-resources-contents|>>]]
- [VMware PowerCLI Blog](https://blogs.vmware.com/PowerCLI/)
- [PowerCLI Cookbook for vSAN](https://core.vmware.com/resource/powercli-cookbook-vsan)
- VMware 开发资源 [[vsv-dev-resources-contents|>>]]
- [VMware PowerCLI](https://developer.vmware.com/web/tool/13.2/vmware-powercli/)
- [VMware PowerCLI User's Guide - PowerCLI User's Guide](https://developer.vmware.com/docs/15315/)
- [Compatibility Matrixes for VMware PowerCLI](https://developer.vmware.com/docs/19320/)
- [VMware PowerCLI Reference](https://developer.vmware.com/docs/powercli/latest/products/)
- [GitHub - vmware/PowerCLI-Example-Scripts](https://github.com/vmware/PowerCLI-Example-Scripts)
- 专家资源 [[vsv-sme-resources-contents|>>]]
- 其他资源 [[other-resources|>>]]