Hi Guys,
In my previous post, I explained that how can you automate power on operation using vrops but what about those guys who don't have vROPS and having need to automate such operations. For those guys, I have created a simple but logical powershell function which you can use and it works just fine.
You need to run this script from the jump server where your vcenter is accessible. On that machine, you can also create task scheduler to run this script on every startup of the machine (Because restarting the machine will stop the running script).
This is Power-On example but you can do n number of automation using this logic. Here is the script-
Tell me in my comments that what else you can think to automate in this way.
-----------------------------------------------------------------------------------------------------------------------------
Connect-VIServer vcenter_IP_or_FQDN
Function AutoPower
{
foreach($vmlist in (Get-Content -Path C:\TEMP\vms.txt)){
$vm = Get-VM -Name $vmlist
If ($vm.powerstate -eq "PoweredOff"){
Start-VM -VM $vm -Confirm:$false -ErrorAction SilentlyContinue
Function AutoPower
{
foreach($vmlist in (Get-Content -Path C:\TEMP\vms.txt)){
$vm = Get-VM -Name $vmlist
If ($vm.powerstate -eq "PoweredOff"){
Start-VM -VM $vm -Confirm:$false -ErrorAction SilentlyContinue
}
}
AutoPower
}
AutoPower
}
AutoPower
}
AutoPower
-----------------------------------------------------------------------------------------------------------------------------
You need to save VM's name in a txt or csv file and then give that location in above script.
Below is the video demonstrating the function of the same. This will open up you mind to do many such actions on vCenter server. Feel free to comment if any doubt.
Thank you,
vCloudNotes
0 Comments:
Post a Comment