Automation

 View Only
  • 1.  Can set to True but not to False

    Posted Nov 24, 2008 12:07 PM

    Hi,

    I've been using this script to set the timesync of a VM to TRUE. But I can't seem to set it to false.

    Connect-VIServer 
    [http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("vmware.vim")
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
    $vmConfigSpec.Tools.syncTimeWithHost = "TRUE"
    Get-VM -name "VMWSV339" | % { (Get-View $_.ID).ReconfigVM($vmConfigSpec)}

    I thought that changing TRUE to FALSE would do the trick, but it doesn't.....

    Why not?

    Message was edited by: halr9000 ** reformatted code with tags



  • 2.  RE: Can set to True but not to False
    Best Answer

    Posted Nov 24, 2008 12:35 PM

    Hi,

    The value which you are setting in property is string while it is expecting this value in boolean. Please chenge the line of code as below and try it.

    $vmConfigSpec.Tools.syncTimeWithHost = $false // For false

    $vmConfigSpec.Tools.syncTimeWithHost = $true // For true

    Thanks

    Niket



  • 3.  RE: Can set to True but not to False

    Posted Nov 24, 2008 01:27 PM

    Thanks... life can be so simple



  • 4.  RE: Can set to True but not to False

    Posted Nov 24, 2008 12:37 PM

    With PowerShell you have to use $true or $false for boolean properties.

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
    $vmConfigSpec.Tools.syncTimeWithHost = $false
    
    Get-VM -name "VMWSV339" | % { (Get-View $_.ID).ReconfigVM($vmConfigSpec)}
    



  • 5.  RE: Can set to True but not to False

    Posted Nov 24, 2008 02:10 PM

    Note that once you perform a connection using connect-viserver, the [http://VMware.Vim|http://VMware.Vim] namespace is loaded into your session. You don't need to load it manually.

    PowerShell MVP, VI Toolkit forum moderator

    Author of the upcoming book: Managing VMware Infrastructure with PowerShell

    Co-Host, PowerScripting Podcast (http://powerscripting.net)

    Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org