profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Sunday, August 9, 2015

Configuring the VM's hardware settings via Powercli

I am pretty sure you have come across situations where you had to set the hardware settings of the VMs as per your standard on multiple datacenters or you might have thought about how to do so...
Here is something that might be useful and as always i will keep it updated on my github page.

<#
.SYNOPSIS
    A brief description of the function or script. This keyword can be used
    only once in each topic.
.DESCRIPTION
    A detailed description of the function or script. This keyword can be
    used only once in each topic.
.NOTES
    File Name      : VMsettings.ps1
    Author         : gajendra d ambi
    Time           :
    Prerequisite   : PowerShell V2 over Vista and upper.
    Copyright      - None
.LINK
    Script posted over:
   
#>

#Fill these details
$vc = ""
$db = ""
$um = ""

#If using in powershell then add snapins below
Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

#Disconnect from already connected viservers if any
Disconnect-VIServer * -ErrorAction SilentlyContinue

#Get host's details
$host = Read-Host "address of the esxi host on which the VMs are deployed?"
$user = "root"
$pass = Read-Host "Password for the esxi host?"
Connect-VIServer $host -User $user -Password $pass

#vCenter Server
#change memory and cpu
get-vm $vc | Set-VM -NumCpu 6 -MemoryGB 20 -Confirm:$false
#grow the 1st 2 harddisks
(Get-HardDisk -vm $vc)[0] | Set-HardDisk -CapacityGB 60 -Confirm:$false
(Get-HardDisk -vm $vc)[1] | Set-HardDisk -CapacityGB 40 -Confirm:$false
#add 2 additional hard disks and provision them as thin
New-HardDisk -vm $vc -CapacityGB 40 -StorageFormat Thin -Confirm:$false
New-HardDisk -vm $vc -CapacityGB 40 -StorageFormat Thin -Confirm:$false
Write-host ""

#database server
#change memory and cpu
get-vm $db | Set-VM -NumCpu 4 -MemoryGB 16 -Confirm:$false
#grow harddisks
(Get-HardDisk -vm $db)[0] | Set-HardDisk -CapacityGB 60 -Confirm:$false
(Get-HardDisk -vm $db)[1] | Set-HardDisk -CapacityGB 60 -Confirm:$false
(Get-HardDisk -vm $db)[2] | Set-HardDisk -CapacityGB 60 -Confirm:$false
(Get-HardDisk -vm $db)[3] | Set-HardDisk -CapacityGB 60 -Confirm:$false
Write-host ""

#update manager
#change memory and cpu
get-vm $um | Set-VM -NumCpu 4 -MemoryGB 8 -Confirm:$false
#grow harddisks
(Get-HardDisk -vm $um)[0] | Set-HardDisk -CapacityGB 50 -Confirm:$false
(Get-HardDisk -vm $um)[1] | Set-HardDisk -CapacityGB 50 -Confirm:$false
Write-host ""
 

No comments:

Post a Comment