PowerShellVMware

Configuring Your PowerShell to run VMware vSphere PowerCLI cmdlets

If you are new to even PowerShell, you need get your base PowerShell configured to run the cmdlets.  You may want to take a look at Setting up environment for PowerShell scripting

 

Configure Your PowerShell successfully run the cmdlets in VMware vSphere PowerCLI:

Launch VMware vSphere PowerCLI as Administrator on the system you are running:

          Welcome to the VMware vSphere 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) 1998-2013 VMware, Inc. All rights reserved.

PowerCLI C:Windowssystem32>

 

Check the PowerCLIConfiguration about InvalidCertificateAction:  By Default it’ll be UNSET  and you need to set it to IGNORE.

 

PowerCLI C:> Get-PowerCLIConfiguration

Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayDeprecationWarnings WebOperationTimeout

Seconds

—– ———– ——————- ———————— ————————– ——————-

Session UseSystemProxy Multiple Unset True 300

User

AllUsers

PowerCLI C:>

image

 

Without setting it, if you try to connect to your VMHost, make connection to your VMware Host server, you’ll get a warning message as given below:

 

PowerCLI C:> Connect-VIServer VMHOST01

WARNING: There were one or more problems with the server certificate:

* The X509 chain could not be built up to the root certificate.

* The certificate’s CN name does not match the passed value.

Certificate: [Subject]

OID.xxxxxxxxxxx="xxxxxxxxxxx,xxxxxxxxxxx", CN=localhost.localdomain,

E=ssl-certificates@vmware.com, OU=VMware ESX Server Default Certificate, O="VMware, Inc", L=Palo Alto, S=California,C=US

[Issuer]

O=VMware Installer

[Serial Number]

XXXXXXXXXXXX

[Not Before]

XX/XX/XXXX XX:XX:XX AM

[Not After]

XX/XX/XXXX XX:XX:XX AM

[Thumbprint]

XXXXXXXXXXXXXXXXXXXXXXXXXX

The server certificate is not valid.

WARNING: THE DEFAULT BEHAVIOR UPON INVALID SERVER CERTIFICATE WILL CHANGE IN A FUTURE RELEASE. To ensure scripts are

not affected by the change, use Set-PowerCLIConfiguration to set a value for the InvalidCertificateAction option.

Specify Credential

Please specify server credential

User:

User:

User:

User: root

Password for user root: **********

Name Port User

—- —- —-

VMHOST01 443 root

PowerCLI C:>

Use Set-PowerCLIConfiguration to set the default action for InvalidCertificateAction. To run Set-PowerCLIConfiguration cmdlet you need to be running your PowerShell console as Administrator otherwise you’ll encounter below error: 

PowerCLI C:> Set-PowerCLIConfiguration -InvalidCertificateAction ignore -Confirm:$False
Set-PowerCLIConfiguration : Only administrators can change settings for all users.
At line:1 char:1
+ Set-PowerCLIConfiguration -InvalidCertificateAction ignore -Confirm:$False
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-PowerCLIConfiguration], InvalidArgument
    + FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidArgument,VMware.VimAutomation.
   ViCore.Cmdlets.Commands.SetVIToolkitConfiguration

PowerCLI C:>

 

When you run the Set-PowerCLIConfiguration with Administrator privileges it’ll complete as shown below:

PowerCLI C:> Set-PowerCLIConfiguration -InvalidCertificateAction ignore -Confirm:$False

Scope    ProxyPolicy     DefaultVIServerMode InvalidCertificateAction  DisplayDeprecationWarnings WebOperationTimeout
                                                                                                  Seconds
—–    ———–     ——————- ————————  ————————– ——————-
Session  UseSystemProxy  Multiple            Ignore &#1
60;                  True                       300
User
AllUsers                                     Ignore

PowerCLI C:> Get-PowerCLIConfiguration

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

PowerCLI C:>

image

 

Once you are all set with configuring InvalidCertificateAction, Disconnect connection to server and Exit from existing PowerShell.

 

Launch the VMware vSphere PowerCLI console again, and now when you try to connect to the VMHost it’ll connect without any warnings as shown below:

 

PowerCLI C:> Connect-VIServer VMHOST01

Specify Credential
Please specify server credential
User: root
Password for user root: ************

Name                           Port  User
—-                           —-  —-
VMHOST01                       443   root

PowerCLI C:>

 

First time connecting to your vCenter server:

You’ll land up if you attempt to connect to your vCenter server before you configure your

 

 

PowerCLI C:> Connect-VIServer 172.232.1.123

Specify Credential

Please specify server credential

User: root

Password for user root: ******

Connect-VIServer : 7/10/2013 7:20:01 PM Connect-VIServer Expected DTD markup was not found. Line 3, position

3.

At line:1 char:1

+ Connect-VIServer 172.232.1.123

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [Connect-VIServer], ViError

+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Exception,VMware.VimAutomation.ViCore.Cmdlets

.Commands.ConnectVIServer

PowerCLI C:> Connect-VIServer 172.232.1.123

Specify Credential

Please specify server credential

User: root

Password for user root: ******

Name Port User

—- —- —-

172.232.1.123 443 root

PowerCLI C:> Connect-VIServer 172.232.1.123

Connect-VIServer : 7/10/2013 7:32:30 PM Connect-VIServer Network connectivity error occured. Please verify

that the network address and port are correct.

At line:1 char:1

+ Connect-VIServer 172.222.1.123

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (:) [Connect-VIServer], ViServerConnectionException

+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_BadNetworkConnection,VMware.VimAutomation.ViC

ore.Cmdlets.Commands.ConnectVIServer

PowerCLI C:>

 

 

Working with multiple Default servers?

 

PowerCLI C:> Connect-VIServer -Server 172.232.1.123

Specify Credential
Please specify server credential
User: root
Password for user root: ********

Working with multiple default servers?

    Select [Y] if you want to work with more than one default servers. In this case, every time when you connect to a
different server using Connect-VIServer, the new server connection is stored in an array variable together with the
previously connected servers. When you run a cmdlet and the target servers cannot be determined from the specified
parameters, the cmdlet runs against all servers stored in the array variable.
    Select [N] if you want to work with a single default server. In this case, when you run a cmdlet and the target
servers cannot be determined from the specified parameters, the cmd
let runs against the last connected server.

    WARNING: WORKING WITH MULTIPLE DEFAULT SERVERS WILL BE ENABLED BY DEFAULT IN A FUTURE RELEASE. You can explicitly
set your own preference at any time by using the DefaultServerMode parameter of Set-PowerCLIConfiguration.

[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y

Name                           Port  User
—-                           —-  —-
172.232.1.123                  443   root

PowerCLI C:>

Advertisements