简体   繁体   English

在VMware VCenter连接自动化中运行powershell / powercli脚本

[英]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. 我正在从Ubuntu运行一组powerCLI脚本,以连接到VCenter进行大量配置更改。 Every script is invoked via SSH, so it is connecting and disconnecting to the VCenter everytime. 每个脚本都是通过SSH调用的,因此它每次都与VCenter连接和断开连接。 This is rather time consuming, is it possible to setup powerCLI/powershell environment to connect to a VCenter automatically? 这非常耗时,是否可以设置powerCLI / powershell环境以自动连接到VCenter? Or, maintain a session of a powerCLI/powershell so remote connections can re-use it? 或者,维护powerCLI / powershell的会话,以便远程连接可以重新使用它? 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. 您可以使用PowerCLI6.5.1来完成大部分要求。 Install from the PowerShell gallery. 从PowerShell库安装。

Find the Module Find-Module -Name VMware.PowerCLI 查找模块Find-Module-名称VMware.PowerCLI

Install Install-Module -Name VMware.PowerCLI –Scope CurrentUser 安装Install-Module-名称VMware.PowerCLI –作用域CurrentUser

if you run into an error during installation I fixed it with AllowClobber "-AllowClobber" command 如果您在安装过程中遇到错误,请使用AllowClobber“ -AllowClobber”命令修复它

Import-Module VMware.PowerCLI 导入模块VMware.PowerCLI

A couple of examples 几个例子

Connect-VIServer "Server" -SessionId $sessionId Connect-VIServer“服务器” -SessionId $ sessionId

Connect to a server and save the session ID - $serverObject.SessionId You will be able to restore a existing server connection. 连接到服务器并保存会话ID-$ serverObject.SessionId您将能够还原现有服务器连接。

Connect-VIServer "Server" -User user -Password pass -SaveCredentials Connect-VIServer“服务器”-用户-密码传递-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 有关更多信息,请参见此处https://blogs.vmware.com/PowerCLI/2017/04/powercli-install-process-powershell-gallery.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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