【vSphere | PowerCLI】安装 PowerCLI

1. 在线安装PowerCLI

1.1 命令

Install-Module -Name VMware.PowerCLI

示例

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> Install-Module -Name VMware.PowerCLI

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with
NuGet-based repositories. The NuGet provider must be available in 'C:\Program
Files\PackageManagement\ProviderAssemblies' or
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'. You can also
install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion
2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are
you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
PS C:\Users\Administrator>

在这里插入图片描述
在这里插入图片描述

安装时间以网速下载快慢为准。

2. 安装离线版PowerCLI

2.1下载离线安装包

下载链接:VMware PowerCLI
在这里插入图片描述

2.2 解压压缩包

将下载的安装包解压并打开。
在这里插入图片描述

(1)方法1- 官方方法

(1)在本地计算机上打开 PowerShell。

(2)查看已解压缩 PowerCLI ZIP 文件的文件夹路径,运行命令:$env:PSModulePath

(3)运行命令以解锁复制的文件:Get-ChildItem -Path 'folder_path' -Recurse | Unblock-File
将 folder_path 替换为解压缩 ZIP 文件内容的文件夹路径。

(4)验证 VMware PowerCLI 模块是否已成功安装。

获取模块: VMware* -ListAvailable

在这里插入图片描述

PS C:\Users\yz> $env:PSModulePath
C:\Users\yz\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\yz> Get-ChildItem -Path 'C:\Program Files\WindowsPowerShell\Modules' -Recurse | Unblock-File
PS C:\Users\yz> Get-Module VMware* -ListAvailable


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     12.6.0.... VMware.CloudServices                {Connect-Vcs, Disconnect-Vcs, Get-VcsOrganizationRole, Get-VcsService...}
Script     8.0.0.2... VMware.DeployAutomation             {Add-CustomCertificate, Add-DeployRule, Add-ProxyServer, Add-ScriptBundle...}
Script     8.0.0.2... VMware.ImageBuilder                 {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, Export-EsxImageProfile...}
Manifest   13.1.0.... VMware.PowerCLI
Script     12.6.0.... VMware.PowerCLI.Sdk
Script     12.6.0.... VMware.PowerCLI.Sdk.Types
Script     12.6.0.... VMware.PowerCLI.VCenter             {Get-VIMachineCertificate, Get-VITrustedCertificate, Remove-VITrustedCertificate, New-VIMachineCertificateSigningRequest...}
Script     12.6.0.... VMware.PowerCLI.VCenter.Types.Ap...
Script     12.6.0.... VMware.PowerCLI.VCenter.Types.Ce...
Script     4.1.0.2... VMware.Sdk.Nsx.Policy               {Connect-NsxServer, Connect-NsxVmcServer, Disconnect-NsxServer, Disconnect-NsxVmcServer...}
Script     1.0.111... VMware.Sdk.Runtime                  {Get-ServerConfiguration, New-ServerConfiguration, Add-ServerConfiguration, Set-ServerConfiguration...}
Script     8.7.0.2... VMware.Sdk.Srm                      {Connect-SrmSdkServer, Disconnect-SrmSdkServer, Get-SrmOperation, Initialize-SrmAbrProtectionGroupSpec...}
Script     8.7.0.2... VMware.Sdk.Vr                       {Connect-VrServer, Disconnect-VrServer, Get-VrOperation, Initialize-VrConfigureReplicationSpec...}
Manifest   8.0.111... VMware.Sdk.vSphere
Script     8.0.111... VMware.Sdk.vSphere.Appliance        {Invoke-GetItemHealthMessages, Invoke-GetHealthSettings, Invoke-UpdateHealthSettings, Invoke-CreateLocalAccounts...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Access {Invoke-GetAccessConsolecli, Invoke-SetAccessConsolecli, Invoke-GetAccessDcui, Invoke-SetAccessDcui...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Health {Invoke-GetHealthApplmgmt, Invoke-GetHealthDatabase, Invoke-GetHealthDatabaseStorage, Invoke-GetHealthLoad...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Inf... {Invoke-ExportInfraprofileConfigs, Invoke-ImportInfraprofileConfigsAsync, Invoke-ListInfraprofileConfigs, Invoke-ValidateInfraprofileConfigsAsync...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Loc... {Invoke-GetLocalAccountsGlobalPolicy, Invoke-SetLocalAccountsGlobalPolicy, Initialize-LocalAccountsPolicyInfo}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Log... {Invoke-GetLoggingForwarding, Invoke-SetLoggingForwarding, Invoke-TestLoggingForwarding, Initialize-LoggingForwardingConfig...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Net... {Invoke-CreateNetworkingDnsDomains, Invoke-ListNetworkingDnsDomains, Invoke-SetNetworkingDnsDomains, Invoke-GetNetworkingDnsHostname...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Rec... {Invoke-GetSystemNameArchive, Invoke-ListSystemNameArchives, Invoke-ValidateRecoveryBackup, Invoke-ListBackupJobDetails...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Sup... Invoke-GetSupportBundleComponents
Script     8.0.111... VMware.Sdk.vSphere.Appliance.System {Invoke-GetSystemGlobalFips, Invoke-SetSystemGlobalFips, Invoke-ListSystemStorage, Invoke-ResizeExSystemStorage...}
Script     8.0.111... VMware.Sdk.vSphere.Appliance.Update {Invoke-InstallVersionPending, Invoke-ListUpdatePending, Invoke-PrecheckVersionPending, Invoke-StageAndInstallVersionPending...}
Script     8.0.111... VMware.Sdk.vSphere.Cis              {Invoke-CreateSession, Invoke-DeleteSession, Invoke-GetSession, Invoke-CancelTask...}
Script     8.0.111... VMware.Sdk.vSphere.Cis.Tagging      {Invoke-AddToUsedByCategoryId, Invoke-CreateCategory, Invoke-DeleteCategoryId, Invoke-GetCategoryId...}
Script     8.0.111... VMware.Sdk.vSphere.Content          {Invoke-GetContentConfiguration, Invoke-UpdateContentConfiguration, Invoke-FindContentLibrary, Invoke-GetLibraryIdContent...}
Script     8.0.111... VMware.Sdk.vSphere.ContentLibrary   {Invoke-GetLibraryItemVersionLibraryChanges, Invoke-ListLibraryItemContentChanges, Invoke-CancelDownloadSessionId, Invoke-CreateLibraryItemDownloadSession...}
Script     8.0.111... VMware.Sdk.vSphere.Esx.Hcl          {Invoke-DownloadHclCompatibilityDataAsync, Invoke-GetHclCompatibilityDataStatus, Invoke-ListHostHclCompatibilityReleases, Invoke-CreateHostCompatibilityReportAsync...}
Script     8.0.111... VMware.Sdk.vSphere.Esx.Hosts        {Invoke-ListHostSoftwareInstalledComponents, Invoke-GetSoftware, Initialize-HostsSoftwareHostCredentials}
Script     8.0.111... VMware.Sdk.vSphere.Esx.Settings     {Invoke-DeleteClusterDraftSoftwareAddOn, Invoke-DeleteHostDraftSoftwareAddOn, Invoke-GetClusterDraftSoftwareAddOn, Invoke-GetClusterSoftwareAddOn...}
Script     8.0.111... VMware.Sdk.vSphere.VAPI.Metadata    {Invoke-GetCliCommand, Invoke-GetCliCommandFingerprint, Invoke-ListMetadataCliCommand, Invoke-GetComponentIdAuthentication...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter          {Invoke-GetCluster, Invoke-ListCluster, Invoke-CreateDatacenter, Invoke-DeleteDatacenter...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Authe... Invoke-CreateAuthenticationToken
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Autho... {Invoke-GetAuthorizationPrivilegeChecksLatest, Invoke-ListAuthorizationPrivilegeChecks, Initialize-AuthorizationPrivilegeChecksFilterSpec, Initialize-AuthorizationPrivilegeChecksListRequestBody...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.CertM... {Invoke-GetCertificateManagementSigningCertificate, Invoke-RefreshSigningCertificate, Invoke-SetCertificateManagementSigningCertificate, Invoke-GetCertificateManagementTls...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Consu... {Invoke-AddZoneAssociations, Invoke-GetZoneClusterAssociations, Invoke-RemoveZoneAssociations, Invoke-ListConsumptionDomainsZoneAssociationsCluster...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Content  {Invoke-CreateContentRegistriesHarbor, Invoke-DeleteRegistryRegistriesHarbor, Invoke-GetRegistryRegistriesHarbor, Invoke-ListContentRegistriesHarbor...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Datas... Invoke-GetDatastoreDefaultPolicy
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Deplo... {Invoke-CheckMigrateActiveDirectory, Invoke-CancelDeploymentHistory, Invoke-GetDeploymentHistory, Invoke-PauseDeploymentHistory...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Guest    {Invoke-CreateGuestCustomizationSpecs, Invoke-DeleteNameGuestCustomizationSpecs, Invoke-ExportNameCustomizationSpecs, Invoke-GetNameGuestCustomizationSpecs...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.HVC      {Invoke-AddManagementAdministrators, Invoke-GetHvcManagementAdministrators, Invoke-RemoveManagementAdministrators, Invoke-SetHvcManagementAdministrators...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Identity {Invoke-GetTenantBrokerAdminClient, Invoke-GetBrokerTenantsOperatorClient, Invoke-CreateIdentityProviders, Invoke-DeleteProviderIdentity...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Inven... {Invoke-GetInventoryDatastore, Invoke-GetInventoryNetwork}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.ISO      {Invoke-MountIsoImage, Invoke-UnmountIsoImage, Initialize-IsoImageMountRequestBody, Initialize-IsoImageUnmountRequestBody}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.LCM      {Invoke-CreateLcmDiscoveryAssociatedProducts, Invoke-DeleteProductDiscoveryAssociatedProducts, Invoke-GetProductDiscoveryAssociatedProducts, Invoke-ListLcmDiscoveryAssociatedProducts...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Names... {Invoke-ListNamespaceManagementSoftwareClusterAvailableVersions, Invoke-GetNamespaceManagementClusterCompatibilityV2, Invoke-ListNamespaceManagementClusterCompatibility, Invoke-DisableCluster...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Names... {Invoke-CreateNamespaceDomainSubjectAccess, Invoke-DeleteNamespaceDomainSubjectAccess, Invoke-GetNamespaceDomainSubjectAccess, Invoke-SetNamespaceDomainSubjectAccess...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.OVF      {Invoke-ListOvfExportFlag, Invoke-ListOvfImportFlag, Invoke-CreateOvfLibraryItem, Invoke-DeployOvfLibraryItemId...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Services {Invoke-GetService, Invoke-GetServices, Invoke-RestartService, Invoke-StartService...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Storage  {Invoke-ListPoliciesEntitiesCompliance, Invoke-CheckCompatibilityPolicyPolicies, Invoke-ListStoragePolicies, Invoke-ListPoliciesComplianceVm...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Syste... {Invoke-GetSystemConfigDeploymentType, Invoke-SetSystemConfigDeploymentType, Invoke-GetSystemConfigPscRegistration, Invoke-RepointSystemConfigPscRegistration...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Tagging  Invoke-ListAssociations
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Topology {Invoke-GetNodeTopology, Invoke-ListTopologyNodes, Invoke-ListTopologyReplicationStatus}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Trust... {Invoke-CreateTrustedInfrastructureTrustAuthorityHostsAttestation, Invoke-GetHostTrustedInfrastructureAttestation, Invoke-DeleteClusterVersionBaseImagesAsync, Invoke-GetClusterBaseImagesAsync...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.VCHA     {Invoke-GetClusterActive, Invoke-DeployVchaClusterAsync, Invoke-FailoverVchaClusterAsync, Invoke-GetVchaCluster...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.Vm       {Invoke-GetVmHardwareBoot, Invoke-UpdateVmHardwareBoot, Invoke-ConnectVmCdrom, Invoke-CreateVmHardwareCdrom...}
Script     8.0.111... VMware.Sdk.vSphere.vCenter.VmTem... {Invoke-CheckInTemplateLibraryItemVmCheckOuts, Invoke-CheckOutTemplateLibraryItemCheckOuts, Invoke-DeleteTemplateLibraryItemVmVmTemplateCheckOuts, Invoke-GetTemplateLibraryItemVmVmTemplateCheckOuts...}
Script     8.0.111... VMware.Sdk.vSphere.vStats           {Invoke-CreateStatsAcqSpecs, Invoke-DeleteIdStatsAcqSpecs, Invoke-GetIdStatsAcqSpecs, Invoke-ListStatsAcqSpecs...}
Script     8.0.111... VMware.Sdk.vSphereRuntime           {New-vSphereServerConfiguration, Get-vSphereServerConfiguration, Set-vSphereServerConfiguration, Set-vSphereServerConfigurationApiKey...}
Script     8.1.0.2... VMware.Vim
Script     13.1.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer, Disconnect-CisServer, Get-CisService}
Script     13.1.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}
Script     13.1.0.... VMware.VimAutomation.Common         {Get-PowerCLIContext, Get-Task, New-OAuthSecurityContext, Stop-Task...}
Script     13.1.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHost, Add-VMHostNtpServer...}
Script     13.0.0.... VMware.VimAutomation.Hcx            {Connect-HCXServer, Disconnect-HCXServer, Get-HCXAppliance, Get-HCXComputeProfile...}
Script     13.1.0.... VMware.VimAutomation.HorizonView    {Connect-HVServer, Disconnect-HVServer}
Script     12.0.0.... VMware.VimAutomation.License        Get-LicenseDataManager
Script     13.1.0.... VMware.VimAutomation.Nsxt           {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtGlobalManagerService, Get-NsxtPolicyService...}
Script     13.1.0.... VMware.VimAutomation.Sdk            {Get-ErrorReport, Get-PSVersion, EnableParameterCompleters, Get-InstallPath}
Script     13.1.0.... VMware.VimAutomation.Security       {Add-AttestationServiceInfo, Add-KeyProviderServiceInfo, Add-TrustAuthorityKeyProviderServer, Add-TrustAuthorityKeyProviderServerCertificate...}
Script     12.7.0.... VMware.VimAutomation.Srm            {Connect-SrmServer, Disconnect-SrmServer}
Script     13.1.0.... VMware.VimAutomation.Storage        {Add-EntityDefaultKeyProvider, Add-KeyManagementServer, Add-VsanFileServiceOvf, Add-VsanObjectToRepairQueue...}
Script     1.6.0.0    VMware.VimAutomation.StorageUtility Update-VmfsDatastore
Script     13.1.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSwitch...}
Script     13.0.0.... VMware.VimAutomation.Vmc            {Add-VmcSddcHost, Connect-Vmc, Disconnect-Vmc, Get-AwsAccount...}
Script     13.1.0.... VMware.VimAutomation.vROps          {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinition...}
Script     12.4.0.... VMware.VimAutomation.WorkloadMan... {Disable-WMCluster, Enable-WMCluster, Get-WMCluster, Get-WMNamespace...}
Script     12.7.0.... VMware.VumAutomation                {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}

(2)方法 2

打开powershell,cd到解压的powercli文件夹下

cd C:\Users\yz\Desktop\VMware-PowerCLI-13.1.0-21624340

配置远程执行策略为允许。

PS C:\Users\yz\Desktop\VMware-PowerCLI-13.1.0-21624340> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A
PS C:\Users\yz\Desktop\VMware-PowerCLI-13.1.0-21624340> Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCeip $false -InvalidCertificateAction Ignore
WARNING: Please consider joining the VMware Customer Experience Improvement Program, so you can help us make PowerCLI a
 better product. You can join using the following command:

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

VMware's Customer Experience Improvement Program ("CEIP") provides VMware with information that enables VMware to
improve its products and services, to fix problems, and to advise you on how best to deploy and use our products.  As
part of the CEIP, VMware collects technical information about your organization’s use of VMware products and services
 on a regular basis in association with your organization’s VMware license key(s).  This information does not
personally identify any individual.

For more details: type "help about_ceip" to see the related help article.

To disable this warning and set your preference use the following command and restart PowerShell:
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true or $false.

Perform operation?
Performing operation 'Update VMware.PowerCLI configuration.'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): A

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
-----    -----------     ------------------- ------------------------  -------------------------- -------------------
Session  UseSystemProxy  Multiple            Ignore                    True                       300
User
AllUsers                                     Ignore

参考资料

  • 11
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
PowerCLI是一款VMware vSphere管理工具,基于Windows PowerShell语言。通过PowerCLI,管理员可以自动化VMware vSphere的管理,以提高管理过程的效率。本文将从安装、连接vSphere、使用PowerCLI对象、执行基础的管理操作等几个方面详细介绍PowerCLI的使用。 第一步是安装PowerCLI。在下载和安装PowerCLI之前,需要确保已将PowerShell安装在管理员电脑上,并启用了PowerShell执行策略。安装完成后,可以通过Connect-VIServer命令连接vSphere。 使用PowerCLI对象是PowerCLI的核心。PowerCLI对象是与vSphere环境进行交互的基本单位。它由可操作的属性和方法组成,表示vSphere中的一个对象,如VM、ESXi主机、数据中心等。通过创建PowerCLI对象,管理员可以创建、修改和删除vSphere中的各种对象。同时,还可以使用PowerCLI命令来执行基本的操作,如启动、关闭、重启VM等。 执行基础管理操作也是PowerCLI的重要功能。管理员可以使用PowerCLI命令来管理ESXi主机、数据中心、数据存储、VM等资源。例如,可以使用PowerCLI命令来创建、删除VM,添加、移除虚拟网卡,创建虚拟磁盘等。还可以使用PowerCLI命令来监控vSphere环境的性能,如查看ESXi主机的CPU使用率、内存使用率等信息。 总之,PowerCLI是一款强大的自动化管理工具,可以通过使用PowerCLI对象和执行基础管理操作来提高vSphere环境管理的效率和准确性。管理员可以结合自己的需求和实践经验,利用PowerCLI来完成自动化管理任务,从而提高vSphere环境的管理水平和工作效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NOWSHUT

给点饭钱谢谢,我会努力更新!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值