PowerCLI: Get the report of Hot Add / Hot Plug Status of the VMS

#*************************************************************************************************************
# Script Name : HotAddHotPlugStatus.ps1
# Purpose    : Get the report of Hot Add / Hot Plug Status of the VMS
# Date       : 10-03-2017
# - Initial version
# Date       : 08-29-2023
# - Updated with $PSCredential_VMWARE secured credentials
# Author     : www.vmwarearena.com 
# Tweaker    : www.Burwell.tech
#****************************************************************
#Set $PSCredential_VMWARE
$localvmcredFile = "$env:USERPROFILE\localvmcredential.xml"  
  
if(Test-Path $localvmcredFile){  
    $PSCredential_VMWARE = Import-Clixml $localvmcredFile  
}  
else{  
    $localvmusername = "administrator@vsphere.local"
    $PSCredential_VMWARE = Get-Credential -Credential "$localvmusername"  
    $PSCredential_VMWARE | Export-Clixml $localvmcredFile  
}  
#Import-Module VMware.VimAutomation.Core
Import-Module VMware.VimAutomation.PCloud

$VCServer = Read-Host -prompt "What VCenter would you like to connect to?"

$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 $PSCredential_VMWARE -ErrorAction SilentlyContinue -WarningAction 0 | Out-Null

$Result = @()

If ($?){
    $VMs = Get-VM | Select Name, @{N='MemoryHotAddEnabled';E={$_.ExtensionData.Config.MemoryHotAddEnabled}}, @{N='CPUHotAddEnabled';E={$_.ExtensionData.Config.CpuHotAddEnabled}}
    $Result += $VMs
}

$Result | Export-Csv -Path $LogFile -NoTypeInformation

Write-Host "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. That’s it." 

Posted

in

,

by

Tags: