根据状态调用CSV数据和启动VM
我是PowerShell的新手,我想编写一个脚本,该脚本将检查虚拟机的状态IE或停止,然后当主机机器重新启动时,根据VM的状态,重新启动时,它将启动它们或保持它们他们处于停止状态。
到目前为止,我已经编写了一个脚本,该脚本将在启动时自动启动所有本地VM,但是有时我们是出于某种原因关闭VM,并且不希望它重新启动。
我已经开始编写一个脚本,该脚本将所有VM捕获在主机上,并将其写入CSV文件:
get-vm |选择VMNAME,状态,正常时间|导出csv d:\ vm.csv -notypeinformation
这会产生VMNAME和当前状态IE“运行”或“ OFF”
我的计划是每12小时通过任务调度程序运行此脚本,并且启用了PS1脚本运行并抓住VMNAME和状态,并根据数据启动VM,如果该数据启动了,或者如果将值设置为“关闭”,则将其保持在停止
状态写这个简单的方法?
谢谢。
I am very new to Powershell and I am wanting to write a script that will check the status of Virtual Machines i.e running or stopped, then when the host machine reboots depending on the status of the VM's pior the the reboot it will start them or keep them in a stopped state.
So far I have written a script that will auto start all the local VM's on the host machine on start-up, however sometimes we shutdown a VM for a reason and don't want it starting back up again.
I have started writing a script that captures all the VM's on a host and writes it to a CSV file:
Get-VM | select VMName, State, Uptime| Export-CSV D:\VM.csv -NoTypeInformation
This produces the VMName and the current state ie "Running" or "Off"
My plan is to have this script run via a task scheduler every 12hrs and on-start up have a ps1 script run and grab the VMName and State and depending on the data Start the VM if it was previosuly running, or keep it in a stopped state if the value was set to "off"
Is there an easy way to write this?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许以下文章对您有帮助:
使用PowerShell for PowerShell
您可以在
”例如,如果您的CSV文件(vmstatus.csv)具有VM名称和VM状态喜欢:
那么也许您可以在状态为零的情况下重新启动VM
Maybe the following article is helpful to you:
Using Task Scheduler for PowerShell
You can find the documentation of VM PowerShell CMDLET at VM PowerShell cmdlet
So for example if you have CSV file (vmstatus.csv) with VM Name and VM Status like:
then maybe you can restart VM where the status is zero