VMware Cloud Community
umarzuki
Enthusiast
Enthusiast

batch script to start VMs

since my vCenter is a VM inside one of ESXis, i would like to create a batch to achieve below in sequence:

1) check if AD VM on ESXi A or ESXi B then power on AD VM on that ESXi, repeat with listed VMs:

-vCenter

-View Security Server

2) remount NFS datastores that cannot be browsed its contents

3) restart vCenter Update Manager service

thanks in advance

Tags (2)
0 Kudos
3 Replies
LucD
Leadership
Leadership

I suppose you are connected to the vCenter ?

If yes, you can find the name of the vCenter in the $global:defaultVIServer variable.

Then it is a matter of doing

Get-VM -Name $global:defaultViServer.Name |

Select -ExpandProperty VMHost |

Select -ExpandProperty Name

Not quite sure what you mean with question 2).

You can try to access the datastore and when that fails, assume the NFS mount isn't ok.

Use the vimdatastore provider to do this.

To restart a service under Windows with PowerShell, you can use the Restart-Service cmdlet.

If your script is not running on the server where you have the Update Manager service running, you can use the Invoke-VMScript cmdlet to send the line to the server.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
umarzuki
Enthusiast
Enthusiast

this is incase of power failure where i have to power on AD VM, vCenter VM and other realted VMs, so i connects to either ESXi A or ESXi B

what i meant by 2) is sometimes power on sequence of NFS server and ESXi are not in the correct sequence, so NFS will fail to be accessed, so I need to remount on NFS server, then remount of each ESXi that NFS share

what i really what to achieve is when i'm not at the office, i could ask my colleague to simply "double-click on start-vmware.bat on PC 01's desktop" after a power failure

0 Kudos
LucD
Leadership
Leadership

I see.

You could do something withe Copy-DatastoreItem cmdlet, for example copy a file from the datastore to the local file system.

Use the '-ErrorAction SilentlyContinue' parameter.

After the cmdlet finishes you can check if the file is actually copied.

If it is not, remove the NFS datastore and make the connection again.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos