PowerCLI: Configure Log rotation and size options for vmware.log

By default, the virtual machine log file (vmware.log) is rotated as a result of the virtual machine’s Power On or Power Off operation. , In order to limit the total size this can grow to you may configure the log you may configure a log rotation size and level of rotation.

Also, this can add a level of protection where denial of service attack could write information to a log entry where these limits are not configured,as uncontrolled logging could lead to denial of service due to the datastore’s being filled.

In the below example, I am going to configure each VM to have a log rotate size of ‘1,000’ KB (the configuration value is in bytes, so 1,024,000) and set the level of rotation to ’10’. This can be achieved by adding the following to each VMs configuration parameters (VM Options > Advanced).

log.KeepOld = 10
log.rotatesize = 1024000

As I want to configure these settings for a large number of VMs, I can achieve this by using PowerCLI to build a collection of VMs at a cluster object level and  then add these settings.

Firstly, we will connect to our vCenter server and build a collection of VMs from a single cluster by invoking the Get-VM cmdlet.

if (-not (Get-PSSnapin VMware.VimAutomation.Core-ErrorAction SilentlyContinue)) 
    Add-PSSnapin VMware.VimAutomation.Core | Out-Null 

Connect-VIServer server1.domain.local 
$VMs = Get-Cluster cluster1 | Get-VM

For Each VM returned in the collection, we will now add the configuration settings as above, by invoking the cmdlet New-AdvancedSetting specifying the name and value, where the ‘Confirm’ parameter value is False to prevent the script block requiring user interaction.

ForEach ($VM in $VMs)
    Get-VM $VM.Name | New-AdvancedSetting -Name "log.keepOld" -value "10" -Confirm:$false 
    Get-VM $VM.Name | New-AdvancedSetting-Name "log.rotatesize" -value"1024000" -Confirm:$false 


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s