VMware Cloud Community
Techstarts
Expert
Expert

DRS Rule enable

Hallo Team,

I would like to enable or disable DRS Rule.

When I run a simple command like this

$DRSRule = Get-DrsRule -Cluster "CL1" -name "Test"
Set-DrsRule -Rule $DRSRule -Enabled $false

it works but throws below error. can some advice?

 

Set-DrsRule : 08.12.2021 12:37:42 Set-DrsRule The object of type.
"VMware.VimAutomation.ViCore.Impl.V1.Cluster.DrsVMAffinityRuleImpl" cannot be changed to type
"VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsVMAntiAffinityRule".
In line:1 character:1
+ Set-DrsRule -Rule $BBTTest -Enabled $false
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Set-DrsRule], ViError
    + FullyQualifiedErrorId : Client20_ClientSideTaskImpl_ThreadProc_UnhandledException,VMw
   are.VimAutomation.ViCore.Cmdlets.Commands.SetDrsRule

With Great Regards,
Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership

Which PowerCLI version are you using?


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

Techstarts
Expert
Expert

I believe I'm using latest ?

 

VMware PowerCLI 12.4.0 build 18627050

should I use Powershell 7 (i hate this version though)

With Great Regards,
Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership

That is indeed the latest version.

No, you can use PS v5.1.

Those instructions seem to work for me though.
Can you check there are no older modules left behind in your installation?

Get-Module -Name VMware* -ListAvailable

And what does the following return?

Set-DrsRule -Rule 'Test' -Enabled $false


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

Techstarts
Expert
Expert

 

Hello Luc

previously it was in German and now I'm using Englisch language computer. I see Casting error.

 

et-DrsRule : 08.12.2021 14:45:11       Set-DrsRule             Unable to cast object of type
'VMware.VimAutomation.ViCore.Impl.V1.Cluster.DrsVMAffinityRuleImpl' to type
'VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsVMAntiAffinityRule'.
At line:1 char:1
+ Set-DrsRule -Rule $BBTTest -Enabled $true
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DrsRule], ViError
    + FullyQualifiedErrorId : Client20_ClientSideTaskImpl_ThreadProc_UnhandledException,VMware.VimAutomation.ViCore.Cm
   dlets.Commands.SetDrsRule

 

With Great Regards,
Reply
0 Kudos
LucD
Leadership
Leadership

Did you try using OBN and just use the name of the DRS rule, instead of the DRSRule object?


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

Techstarts
Expert
Expert

Does not want to work 🤣

Set-DrsRule -Rule BBT-Test -Enabled $true
Set-DrsRule: Cannot bind parameter 'Rule'. Cannot convert the "BBT-Test" value of type "System.String" to type "VMware.VimAutomation.ViCore.Types.V1.Cluster.DrsRule"
With Great Regards,
Reply
0 Kudos
LucD
Leadership
Leadership

Ok, so the Set-DrsRule cmdlet doesn't take OBN (Object By Name).

I just tested with several DRS rules, I'm on 12.4.1, and they all worked.


drsrule.png

Can you check you don't have any older modules in your installation?
Do

 

Get-Module -Name VMware* -ListAvailable

 

 


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

Techstarts
Expert
Expert

No idea what is going. I checked (attached is the file, in case you wish to check)

But this is newly install OS and has newly install Powercli.

 

With Great Regards,
Reply
0 Kudos
LucD
Leadership
Leadership

Those modules look alright, no problem there as far as I can see.

Do you have this on all stations where you use Set-DrsRule?


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