简体   繁体   中英

Running powershell/powercli scripts in VMware VCenter connection automation

I'm running a set of powerCLI scripts from Ubuntu to connect to VCenter do a bunch of configuration changes. Every script is invoked via SSH, so it is connecting and disconnecting to the VCenter everytime. This is rather time consuming, is it possible to setup powerCLI/powershell environment to connect to a VCenter automatically? Or, maintain a session of a powerCLI/powershell so remote connections can re-use it? One possibility is to use "screen" command to share the session, but i'm hoping someone has a more elegant idea.

You can use PowerCLI6.5.1 to do most of what you are asking. Install from the PowerShell gallery.

Find the Module Find-Module -Name VMware.PowerCLI

Install Install-Module -Name VMware.PowerCLI –Scope CurrentUser

if you run into an error during installation I fixed it with AllowClobber "-AllowClobber" command

Import-Module VMware.PowerCLI

A couple of examples

Connect-VIServer "Server" -SessionId $sessionId

Connect to a server and save the session ID - $serverObject.SessionId You will be able to restore a existing server connection.

Connect-VIServer "Server" -User user -Password pass -SaveCredentials

Will save the credentials to the credential store. That way you can reuse them and they are encrypted.

See here for more info https://blogs.vmware.com/PowerCLI/2017/04/powercli-install-process-powershell-gallery.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM