PowerCLI

 View Only
  • 1.  Trying to Change DRS Advanced Options

    Posted Feb 23, 2010 04:38 PM

    I'm trying to write a quick Powershell script to change the following DRS Advanced option:

    MinPoweredOnCpuCapacity

    Basically, the idea is to set it high during work hours, and bump it down during off hours.

    I've gotten this far, and feel I'm really close:

    connect-viserver

    $view = ( Get-View (Get-Cluster Cluster1).Id)

    I can see the option I've already set here:

    $view.Configuration.DrsConfig.Option

    Key Value DynamicType DynamicProperty

    --- -


    -


    -


    MinPoweredOnCpuCapacity 90000

    Here is how I've tried ot set it:

    $opt = New-Object VMWAre.vim.OptionValue

    $opt.Key = "MinPoweredOnCpuCapacity"

    $opt.Value = 1

    $spec = New-Object VMware.VIm.ClusterConfigSpecEx

    $spec.DrsConfig = New-Object Vmware.vim.ClusterDrsConfigInfo

    $spec.DrsConfig.option = $opt

    $view.ReconfigureComputeResource($spec, $true)

    This last command fails with the following message:

    Exception calling "ReconfigureComputeResource" with "2" argument(s): "A specified parameter was not correct.

    DRS advanced option: MinPoweredOnCpuCapacity"

    At line:1 char:33

    + $view.ReconfigureComputeResource <<<< ($spec, $true)

    + CategoryInfo : NotSpecified: (:smileyhappy: [], MethodInvocationException

    + FullyQualifiedErrorId : DotNetMethodException

    Any ideas on how to do this??

    Thanks!



  • 2.  RE: Trying to Change DRS Advanced Options
    Best Answer

    Posted Feb 23, 2010 06:32 PM

    Contrary to what the SDK Reference says the value property has to be a string.

    This will work

    $opt = New-Object VMWAre.vim.OptionValue
    $opt.Key = "MinPoweredOnCpuCapacity"
    $opt.Value = [string]1
    $spec = New-Object VMware.VIm.ClusterConfigSpecEx
    $spec.DrsConfig = New-Object Vmware.vim.ClusterDrsConfigInfo
    $spec.DrsConfig.option = $opt
    $view.ReconfigureComputeResource($spec, $true)
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: Trying to Change DRS Advanced Options

    Posted Feb 25, 2010 12:11 AM

    That was it. Thank you very much!



  • 4.  RE: Trying to Change DRS Advanced Options

    Posted Mar 30, 2011 04:48 PM

    The information provide is very useful.  My question is do you code for enumerating the contes of the drs rule, the host group and the quest group. This would be helpful to create a baseline of drs rules for monitoring any changes that might occur in the environment.  I will attempt to modify the code provided to get a version for listing, but my skill level for managing these objects is lacking at best.

    Thanks

    Bob