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:
$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: ( [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Any ideas on how to do this??
Thanks!
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That was it. Thank you very much!
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