PowerCLIGoodies / DRSRule

PowerShell module with support for managing vSphere DRS Rules and Groups
29 stars 9 forks source link

Import-DrsRule does not support specifying rule by type #24

Open Nick-Andreev opened 4 years ago

Nick-Andreev commented 4 years ago

It would be nice to be able to specify the rule not only by name, but also by type, when importing DRS rules from a file.

The way it's implemented right now, if I say have a host group called "host2" and VM to host rule "host2" and I call Import-DrsRule with the following parameters:

Import-DrsRule -Cluster "my-cluster" -Path "drs-rule-export.json" -Name "host2"

Cmdlet will attempt to import both the group and the rule, which is not always what you want. This is the bit of code that checks the name:

## if -Name was specified, filter
if ($PSBoundParameters.ContainsKey("Name")) {$arrRuleObjects_filtered = $arrRuleObjects_filtered | Where-Object -FilterScript {$_.Name -like $Name}}

The following piece of code will need to be added to also check for type:

## if -Type was specified, filter
if ($PSBoundParameters.ContainsKey("Type")) {$arrRuleObjects_filtered = $arrRuleObjects_filtered | Where-Object -FilterScript {$_.Type -like $Type}}
Nick-Andreev commented 4 years ago

I don't mind implementing it myself and submitting a pull request. This will require a couple of changes, such as adding a new parameter to Import-DrsRule, changing the function, updating cmdlet help, etc.

If this project is still monitored and you think this addition might be useful, let me know and I can submit the change.