Click or drag to resize

PowerShell

PowerShell and VMware

This topic contains the following sections:

Requirement

This section contains the following subsections:

PowerShell

PowerShell installation see external link to Microsoft

VMware PowerCLI

Install VMware PowerCLI module

  1. Start Windows PowerShell ISE as administrator

  2. Check PowerShell version

    Command: $PSVersionTable

    PowerShell
    PS C:\Windows\system32> $PSVersionTable
    
    Name                           Value                                                                                                  
    ----                           -----                                                                                                  
    PSVersion                      5.1.14409.1005                                                                                         
    PSEdition                      Desktop                                                                                                
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                
    BuildVersion                   10.0.14409.1005                                                                                        
    CLRVersion                     4.0.30319.42000                                                                                        
    WSManStackVersion              3.0                                                                                                    
    PSRemotingProtocolVersion      2.3                                                                                                    
    SerializationVersion           1.1.0.1
  3. Check exists installs of VMware models

    Command: Get-Module VMware* -ListAvailable

    PowerShell
    PS C:\Windows\system32> Get-Module VMware* -ListAvailable

    Result: output must null lines, has list entry then delete the files into folders

    Example folder of install:
    by all users install: C:\Program Files\WindowsPowerShell\Modules
    by user install: C:\Users\SOWI\Documents\WindowsPowerShell\Modules

  4. Check availability of VMware Power CLI module

    Command: Find-Module -Name VMware.PowerCLI

    PowerShell
    PS C:\Windows\system32> Find-Module -Name VMware.PowerCLI
    
    Version    Name                                Repository           Description                                                       
    -------    ----                                ----------           -----------                                                       
    11.5.0.... VMware.PowerCLI                     PSGallery            This Windows PowerShell module contains VMware.PowerCLI
  5. Install VMware Power CLI modules

    Command: Install-Module -Name VMware.PowerCLI -Scope AllUsers -Force

  6. Check the install

    Command: Get-Module VMware* -ListAvailable

    PowerShell
    PS C:\Windows\system32> Get-Module VMware* -ListAvailable
    
    
        Directory: C:\Program Files\WindowsPowerShell\Modules
    
    
    ModuleType Version    Name                                ExportedCommands                                                            
    ---------- -------    ----                                ----------------                                                            
    Script     6.7.0.1... VMware.DeployAutomation             {Add-DeployRule, Add-ProxyServer, Add-ScriptBundle, Copy-DeployRule...}     
    Script     6.7.0.1... VMware.ImageBuilder                 {Add-EsxSoftwareDepot, Add-EsxSoftwarePackage, Compare-EsxImageProfile, E...
    Manifest   11.5.0.... VMware.PowerCLI                                                                                                 
    Script     6.7.0.1... VMware.Vim                                                                                                      
    Script     11.5.0.... VMware.VimAutomation.Cis.Core       {Connect-CisServer, Disconnect-CisServer, Get-CisService}                   
    Script     11.0.0.... VMware.VimAutomation.Cloud          {Add-CIDatastore, Connect-CIServer, Disconnect-CIServer, Get-Catalog...}    
    Script     11.5.0.... VMware.VimAutomation.Common         {Get-Task, Stop-Task, Wait-Task}                                            
    Script     11.5.0.... VMware.VimAutomation.Core           {Add-PassthroughDevice, Add-VirtualSwitchPhysicalNetworkAdapter, Add-VMHo...
    Script     11.5.0.... VMware.VimAutomation.Hcx            {Connect-HCXServer, Disconnect-HCXServer, Get-HCXAppliance, Get-HCXComput...
    Script     7.10.0.... VMware.VimAutomation.HorizonView    {Connect-HVServer, Disconnect-HVServer}                                     
    Script     11.3.0.... VMware.VimAutomation.License        Get-LicenseDataManager                                                      
    Script     11.5.0.... VMware.VimAutomation.Nsxt           {Connect-NsxtServer, Disconnect-NsxtServer, Get-NsxtPolicyService, Get-Ns...
    Script     11.5.0.... VMware.VimAutomation.Sdk            Get-ErrorReport                                                             
    Script     11.0.0.... VMware.VimAutomation.Security       {Get-SecurityInfo, Get-VTpm, Get-VTpmCertificate, Get-VTpmCSR...}           
    Script     11.5.0.... VMware.VimAutomation.Srm            {Connect-SrmServer, Disconnect-SrmServer}                                   
    Script     11.5.0.... VMware.VimAutomation.Storage        {Add-KeyManagementServer, Add-VsanObjectToRepairQueue, Copy-VDisk, Export...
    Script     1.3.0.0    VMware.VimAutomation.StorageUtility Update-VmfsDatastore                                                        
    Script     11.2.0.... VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGro...
    Script     11.5.0.... VMware.VimAutomation.Vmc            {Add-VmcSddcHost, Connect-Vmc, Disconnect-Vmc, Get-AwsAccount...}           
    Script     10.0.0.... VMware.VimAutomation.vROps          {Connect-OMServer, Disconnect-OMServer, Get-OMAlert, Get-OMAlertDefinitio...
    Script     6.5.1.7... VMware.VumAutomation                {Add-EntityBaseline, Copy-Patch, Get-Baseline, Get-Compliance...}

PowerCLI setting

PowerCLI configuration file. The copies of the PowerCLI_settings.xml file on your system contain User and AllUsers settings for PowerCLI.

Configuring PowerCLI by running Set-PowerCLIConfiguration creates a copy of PowerCLI_settings.xml on your system. The location of the PowerCLI_settings.xml file depends on the value of the Scope parameter.

An example

PowerShell
PS C:\Windows\system32> Set-PowerCLIConfiguration -Scope AllUsers

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

Example folder:
by all users install: %SYSTEMDRIVE%\ProgramData\VMware\PowerCLI
by user install: %APPDATA%\Roaming\VMWare\PowerCLI

Note Note

Note: You must have administrator privileges to change the settings for AllUsers. Location of PowerCLI_settings.xml

The setting file PowerCLI_Settings.xml file store in folder

If not exists a PowerCLI setting file then can triggers an exception.

Unable to load settings file : C:\ProgramData\VMware\PowerCLI\PowerCLI_Settings.xml. Error: System.IO.DirectoryNotFoundException: Ein Teil des Pfades "C:\ProgramData\VMware\PowerCLI\PowerCLI_Settings.xml" konnte nicht gefunden werden.

Using
Note Note

Application SOWI VMInfoFace and Microsoft PowerShell module VMware.PowerCLI use same DLLs

  • VMware.Binding.WsTrust.dll

  • VMware.Security.CredentialStore.dll

SOWI VMInfoFace PowerShell commands into VMInfoFace.ShellCommand

The protocol of commands to property CommandResult

Important note Important

SOWI VMInfoFace automatically reads the PowerShell module versions and install.

See method CommandGetVersion

File list for Microsoft PowerShell module VMware.PowerCLI

Folder: %ProgramFiles%\WindowsPowerShell\Modules\VMware.VimAutomation.Common\11.5.0.14898112\net45
File: VMware.Binding.WsTrust.dll
Command: Import-Module -Name '%ProgramFiles%\WindowsPowerShell\Modules\VMware.VimAutomation.Common\11.5.0.14898112\net45\VMware.Binding.WsTrust.dll'

Folder: %ProgramFiles%\WindowsPowerShell\Modules\VMware.VimAutomation.Sdk\11.5.0.14898111\net45
File: VMware.Security.CredentialStore.dll
Command: Import-Module -Name '%ProgramFiles%\WindowsPowerShell\Modules\VMware.VimAutomation.Sdk\11.5.0.14898111\net45\VMware.Security.CredentialStore.dll'

Command: Import-Module -Name VMware.PowerCLI

PowerShell
PS C:\Windows\system32> Import-Module -Name VMware.PowerCLI
          Welcome to VMware PowerCLI!

Log in to a vCenter Server or ESX host:              Connect-VIServer
To find out what commands are available, type:       Get-VICommand
To show searchable help for all PowerCLI commands:   Get-PowerCLIHelp
Once you've connected, display all virtual machines: Get-VM
If you need more help, visit the PowerCLI community: Get-PowerCLICommunity

       Copyright (C) VMware, Inc. All rights reserved.
Commands
Connect-VIServer -Server [IP/DN] -User [user name] -Password [password]

Connect a VMware server

Get-SpbmEntityConfiguration

Get Storage Policy

An example of test script

PowerShell
Import-Module -Name 'C:\Program Files\WindowsPowerShell\Modules\VMware.VimAutomation.Common\11.5.0.14898112\net45\VMware.Binding.WsTrust.dll'
Import-Module -Name 'C:\Program Files\WindowsPowerShell\Modules\VMware.VimAutomation.Sdk\11.5.0.14898111\net45\VMware.Security.CredentialStore.dll'
Import-Module VMware.PowerCLI
Connect-VIServer -Server [ip] -User '[user name]' -Password '[password]'
Get-SpbmEntityConfiguration
See Also