简体   繁体   English

管理powerCLI脚本实例

[英]managing instances of powerCLI script

I wrote a powerCLI script that can automatically deploy a new VM with some given parameters. 我编写了一个powerCLI脚本,该脚本可以使用某些给定参数自动部署新VM。 In few words, the script connects to a given VC and start the deployment from an existing template. 简而言之,该脚本连接到给定的VC,并从现有模板开始部署。

Can I regulate the number of instances of my script that will run on the same computer ? 我可以调节将在同一台计算机上运行的脚本实例的数量吗? Can I regulate the number of instances of my script that will run on different computers but when both instances will be connected to the same VC ? 我可以调节将在不同计算机上运行但两个实例都连接到同一VC的脚本实例的数量吗?

To resolve the issue i thought of developing a server side appilcation where each instance of my script will connect to, and the server will then handle all the instances , but i am not sure if such thing is possible in powerCLI/Powershell. 为了解决该问题,我想到了开发一个服务器端应用程序,脚本的每个实例都将连接到该服务器端,然后服务器将处理所有实例,但是我不确定在powerCLI / Powershell中是否可以实现此目的。

Virtually anything is poshable, or so they say. 他们说,几乎任何事物都是可以享受的。 What you're describing may be overkill, however, depending on your scenario. 但是,根据您的情况,您所描述的可能是过大的。 Multiple instances of the same script will each run in its own Powershell process. 同一脚本的多个实例将在各自的Powershell进程中运行。 Virtual Center allows hundreds of simultaneous connections. Virtual Center允许数百个同时连接。 Of course the content or context of your script might dictate that it shouldn't run in simultaneous instances. 当然,脚本的内容或上下文可能会指示脚本不应在同时实例中运行。 I haven't experimented, but it seems like there are way s to determine the name of running Powershell scripts. 我还没有做过实验,但是似乎有办法确定运行Powershell脚本的名称。 So if you keep the script name consistent on each computer, you could probably build in some checks along the lines of the linked answer. 因此,如果您使每台计算机上的脚本名称保持一致,则可能可以按照链接的答案进行一些检查。

But depending on your particulars, it might be easier to go a different way. 但是,根据您的个人情况,采取其他方式可能会更容易。 For example, if you don't want the script to run simultaneously because you have hard-coded the name of a new-osCustomizationSpec , for example, a simple\\klugey solution might be to do a check for that new spec, and disconnect/exit/rollback if it exists. 例如,如果您不希望脚本同时运行,因为您已经硬编码了new-osCustomizationSpec的名称,那么一个简单的\\ klugey解决方案可能是检查该新规范,然后断开连接/退出/回滚(如果存在)。 A better solution might be to give the new spec a unique name. 更好的解决方案可能是给新规范指定一个唯一的名称。 But the devil is in the details. 但是魔鬼在细节上。 Hope that helps a bit. 希望有点帮助。

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

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