PowerCLI Script – Retrieve VM Memory Hot add & CPU Hot Plug Status

Importance of virtualization is to properly utilize the underlying hardware and resources. In the traditional approach, we run any application on the Guest operating system which is directly installed on the physical hardware. When you really see the usage of memory and CPU on the server hardware will be very less. so we keep the resources ideal without proper utilization. All this traditional approach was washed out by virtualization. Even with server virtualization, Some people tend to get the mindset of over allocating the resources to the virtual machine.  It will cause more pain to the VM, if we allocated more resources what it actually needed.  It would be better you allocate the resources to the virtual machine based on the demand of the VM but VM owners will not be ready to increase the VM resources on demand because of downtime involved for the virtual machines. In vSphere, We have option called ” Memory Hot add & CPU Hot Plug”. This helps us to dynamically increase the CPU & memory on the fly without any downtime to the virtual machines. Memory Hot add & CPU Hot Plug  is supported on most of the recent guest operating systems. Memory Hot add & CPU Hot Plug is disabled by default for any virtual machine. We need to manually enable per VM basis. I am sure all the administrator aware about the procedure to enable & disabled Hot add memory & hot plug CPU in virtual machine properties.

This article with powercli script will help you to export the status of Memory Hot add & CPU Hot Plug settings on all the virtual machines running on any specific vCenter Server. It helps you to export the output to CSV file and can be used for any reporting purposes.

PowerCLI Script – Retrieve VM Memory Hot add & CPU Hot Plug Status

#*************************************************************************************************************
#      Script Name	:   HotAddHotPlugStatus.ps1
#      Purpose		:   Get the report of Hot Add / Hot Plug Status of the VMS
#      Date		:   10-03-2017	# - Initial version
#                   	:  
#      Author		:   www.vmwarearena.com	
#
#*************************************************************************************************************
#
#Import-Module VMware.VimAutomation.Core
Import-Module VMware.VimAutomation.PCloud
$VCServer = Read-Host 'Enter VC Server name'
$vcUSERNAME = Read-Host 'Enter user name'
$vcPassword = Read-Host 'Enter password' -AsSecureString
$vccredential = New-Object System.Management.Automation.PSCredential ($vcusername, $vcPassword)

$LogFile = "VMHotAddHotPlugStatus_" + (Get-Date -UFormat "%d-%b-%Y-%H-%M") + ".csv" 

Write-Host "Connecting to $VCServer..." -Foregroundcolor "Yellow" -NoNewLine
$connection = Connect-VIServer -Server $VCServer -Cred $vccredential -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null
$Result = @()

If($? -Eq $True)

{
	Write-Host "Connected" -Foregroundcolor "Green" 
	Write-Host "Collecting Hot Plug Status of the VMS ..." -Foregroundcolor "Yellow" -NoNewLine
	$Results = @()
	$Result = (Get-VM | select ExtensionData).ExtensionData.config | Select Name, MemoryHotAddEnabled, CpuHotAddEnabled, CpuHotRemoveEnabled
	$Result | Export-Csv -NoTypeInformation $LogFile
	Write-Host "Completed" -Foregroundcolor "Green"
}
Else
{
	Write-Host "Error in Connecting to $VIServer; Try Again with correct user name & password!" -Foregroundcolor "Red" 
}
Disconnect-VIServer * -Confirm:$false
#
#-------------------------------------------------------------------------------------------------------------

How to Execute the Script?

Copy and Paste the above Script and save it in the Notepad. Name the script as “HotAddHotPlugStatus.ps1″

  1. Execute the Script in PowerCLI “.HotAddHotPlugStatus.ps1
  2. Input vCenter Server Name to execute the script to get the report of Memory Hot add & CPU Hot Plug status  of virtual machines
  3. Enter the Username with administrative credentials on vCenter Server
  4. Enter the password for the above entered Username
  5. Hit Enter to execute the script and pull the report.

Memory Hot add & CPU Hot Plug status

 

Script Output

Hot add memory & Hot plug CPU status report will be exported and saved in the Microsoft Excel output file with the filename  “HotAddHotPlugStatus_Today_Day-time.CSV”  under the same directory where the PowerCLI Script  “HotAddHotPlugStatus.ps1″  is located.

VM Memory Hot add & CPU Hot Plug status

That’s it. We are done with the PowerCLI script and got the awesome output with the list of Virtual machines with hot add memory & hot plug CPU status.  I hope this script will be informative for you.  Thanks for Reading!!!. Be social and share it in social media, if you feel worth sharing it.

The post PowerCLI Script – Retrieve VM Memory Hot add & CPU Hot Plug Status appeared first on VMware Arena.


This post was originally published on this site
Comments are closed.