VMware Cloud Community
bolsen
Enthusiast
Enthusiast
Jump to solution

Script to disable VM logging

Can someone help me write a PS script to disable the VM logging check box.

To be clear, if I did this manually the option to uncheck is in VM settings -> Options -> Advanced -> General -> Enable Logging.

TIA

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You build a look that runs over all the VMs in the folder and you place the code above in the loop.

Something like this

$folderName = <folder-name>
Get-Folder $folderName | Get-VM | %{
	$vm = Get-VM $_.Name | Get-View
	$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
	$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
	$spec.flags.enableLogging = $false
	$vm.ReconfigVM($spec)
}

And you can save some CPU cycles and some memory by placing the constant part outside the loop.

Like this

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$spec.flags.enableLogging = $false

$folderName = "PCs"
Get-Folder $folderName | Get-VM | %{
	$vm = Get-VM $_.Name | Get-View
	$vm.ReconfigVM($spec)
}

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Sure, try this

$vmName = <vm-name>

$vm = Get-VM $vmName | Get-View
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$spec.flags.enableLogging = $false
$vm.ReconfigVM($spec)

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
bolsen
Enthusiast
Enthusiast
Jump to solution

Thanks for the quick reply!

If I want to apply this script to all VMs within a folder, what syntax do I need to change?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You build a look that runs over all the VMs in the folder and you place the code above in the loop.

Something like this

$folderName = <folder-name>
Get-Folder $folderName | Get-VM | %{
	$vm = Get-VM $_.Name | Get-View
	$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
	$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
	$spec.flags.enableLogging = $false
	$vm.ReconfigVM($spec)
}

And you can save some CPU cycles and some memory by placing the constant part outside the loop.

Like this

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.flags = New-Object VMware.Vim.VirtualMachineFlagInfo
$spec.flags.enableLogging = $false

$folderName = "PCs"
Get-Folder $folderName | Get-VM | %{
	$vm = Get-VM $_.Name | Get-View
	$vm.ReconfigVM($spec)
}

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos