Automation

 View Only
  • 1.  Script to disable VM logging

    Posted Mar 12, 2010 07:22 PM

    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



  • 2.  RE: Script to disable VM logging

    Posted Mar 12, 2010 07:29 PM

    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



  • 3.  RE: Script to disable VM logging

    Posted Mar 12, 2010 07:41 PM

    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?



  • 4.  RE: Script to disable VM logging
    Best Answer

    Posted Mar 12, 2010 07:49 PM

    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