简体   繁体   English

存储和重复使用 PowerShell Session 加载并连接到 vCenter Server 的 PowerCLI 模块

[英]Store and Re-use PowerShell Session with PowerCLI Module Loaded and Connected to vCenter Server

I have a requirement where, I need to execute 3 PowerShell Scripts and each script connects to PowerCLI and then connects to VCenter Server and executes the code.我有一个要求,我需要执行 3 个 PowerShell 脚本,每个脚本连接到 PowerCLI,然后连接到 VCenter Server 并执行代码。

Ouput of Script-1 is input of Script-2, Output of Script-2 is Input of Script-3. Script-1 的输出是 Script-2 的输入,Script-2 的 Output 是 Script-3 的输入。

The problem that I am facing is the time taken the to load PowerCLI module in each of these scripts and then again the time taken to Connect to vCenter Server in each script.我面临的问题是在每个脚本中加载 PowerCLI 模块所花费的时间,然后是在每个脚本中连接到 vCenter Server 所花费的时间。

All the 3 Scripts execute in sequence, but sometimes they all may run on same server or different servers each.所有 3 个脚本都按顺序执行,但有时它们可能都运行在同一台服务器或不同的服务器上。

Is there a way to save the PowerShell session (Where the PowerCLI module is loaded and as well the Connection to the vCenter remains intact) created by Script-1, so that the same can be used有没有办法保存由Script-1创建的PowerShell session(PowerCLI模块加载的地方,以及与vCenter的连接保持不变),以便可以使用相同的

by Script-2 and Script-3?通过 Script-2 和 Script-3?

I know it may sound a bit crazy, but is there a solution or workaround to store the PowerShell session in some object or session variable or file etc? I know it may sound a bit crazy, but is there a solution or workaround to store the PowerShell session in some object or session variable or file etc?

PowerShell has the notion of profiles. PowerShell 具有配置文件的概念。 You could setup the profile to import PowerCLI every time the PowerShell session is created.您可以设置配置文件以在每次创建 PowerShell session 时导入 PowerCLI。

The connection to the vCenter server is going to be the hard part.与 vCenter 服务器的连接将是困难的部分。 Those sessions time out after periods of inactivity (couple hours, generally) as well as after a total amount of time (several days).这些会话在不活动期(通常是几个小时)以及总时间(几天)之后超时。

If you do want to attempt to re-use sessions, PowerCLI does allow it, with the Session parameter available through Connect-VIServer .如果您确实想尝试重用会话,PowerCLI 确实允许这样做, Session参数可通过Connect-VIServer The session ID is accessible through the following Global variable: $global:DefaultVIServer.SessionId session ID 可通过以下全局变量访问: $global:DefaultVIServer.SessionId

Hopefully that helps.希望这会有所帮助。

暂无
暂无

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

相关问题 在Powershell中存储并重新使用SQL连接字符串 - Store and then re-use sql connection strings in powershell 如何在Powershell / Powercli中列出vCenter(VCSA)服务 - How to list vCenter (VCSA) services in powershell / Powercli 在PowerShell中重用SSH代理 - Re-use SSH agent in PowerShell 在VMware VCenter连接自动化中运行powershell / powercli脚本 - Running powershell/powercli scripts in VMware VCenter connection automation Powershell [ Invoke-WebRequest] is it posible to make copy of Session from a certain point and then re-use session from the saved state? - Powershell [ Invoke-WebRequest] is it posible to make copy of Session from a certain point and then re-use session from the saved state? Powershell重新使用哈希表foreach循环 - Powershell Re-Use a hash Table foreach loop 如何在脚本中使用PowerShell模块而不会在用户会话中加载模块? - How can I use a PowerShell module in a script without leaving the module loaded in the user's session? 脱机 PowerShell 模块安装失败 (PowerCLI) - Offline PowerShell module installation failure (PowerCLI) 对于 VIServer 和 PowerCLI,如何仅在 PowerShell 中第一次提示输入凭据,然后存储凭据并在下次脚本运行时使用它们? - For VIServer and PowerCLI, how to prompt for Credentials only the first time in PowerShell, then store credentials and use them for next script run? 在 Powershell 中,将 PSCustomObjects 数组保存并恢复到文件中,以供以后重新加载和重新使用 - In Powershell, save and restore array of PSCustomObjects to a file for later reload and re-use
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM