Posts

Showing posts from May, 2024

Powering On and Off VMs in vCenter Using Simple PowerCLI Scripts

Here's a simple VMware PowerCLI script to power on and power off VMs from vCenter: Prerequisites: Install VMware PowerCLI on your machine. Ensure you have the necessary permissions to manage VMs in vCenter. Power On VM Script: # Connect to vCenter Server Connect-VIServer -Server vcenter.example.com -User 'username' -Password 'password' # Power on a specific VM by its name $vmName = "VM_Name" $vm = Get-VM -Name $vmName # Check if the VM is powered off and power it on if ($vm.PowerState -eq 'PoweredOff') {     Start-VM -VM $vm     Write-Host "$vmName powered on." } else {     Write-Host "$vmName is already running." } # Disconnect from the vCenter Server Disconnect-VIServer -Server vcenter.example.com -Confirm:$false Power Off VM Script: # Connect to vCenter Server Connect-VIServer -Server vcenter.example.com -User 'username' -Password 'password' # Power off a specific VM by its name $vmName = "VM_Name"...