SE Articles From the Field
Purpose
The intent of the article was to allow for increasing the Virtual Machine RAM for specific users within a pool due to work role or requirements. The powershell script utilizes PowerCLI Set-VM cmdlet to change the VM RAM. By placing a user in a specific AD Group ProfileUnity's Privilege Elevation and Application Launcher modules can be leveraged to initiate the command that was compiled into an EXE.
Steps
1. On the Template image, change the hardware settings to Enable'Memory Hot Plug'
2. Power up the template and Install VMware.PowerCLI component on Template image
Install-Module VMware.PowerCLI -Scope:AllUsers -Force -AllowClobber
3. Shutdown template, snapshot and recompose Non-Persistent pool
4. In vSphere create an account with appropriate permissions to modify a Virtual Machine to be used in Powershell/PowerCLI script.
5. Create a PowerShell script (used Sapien Tools as it will later compile it into an EXE)
#Get Argument from Commandline default to 4GB if nothing passe
parm (
[string]$sizeInGB =4
)
#Set Variables
$envVM =Get-ChileItem env:computername
$vm=$envVM.value
#import modules
Import-Module VMware.PowerCLI
#Setup PowerCLI Environment
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -ParticipateInCeip $false -Confirm $false
#Connect to VirtualCenter
Connect-viserver -server <vcenter name> -Username '<account with perms to modify>' -Password 'password' -ErrorAction Stop
#Check to determine VM Available before attempting to change RAM setting
Get-VM $VM -ErrorAction Stop
$Set the VM's memory in GB, also update Notes field in vSphere to reflect the change was done dynamically
Set-VM -vm $VM -memoryGB $sizeInGB -notes "Dynamic increase to $sizeInGB GB" -Confirm:$false
6. Compile the script into an EXE (ensures the passwords will not be stored in clear text)
In ProfileUnity create a Filter Management to target the Dynamic RAM increase. In my case I created 3 different groups (6GB, 8GB, 12GB)