rubrikinc / rubrik-powershell-sdk

The Rubrik Security Cloud SDK
https://www.powershellgallery.com/packages/RubrikSecurityCloud
MIT License
7 stars 8 forks source link

Change Get-RscVmwareVm -Name to return partial name matches. #139

Closed rynardtspies closed 2 weeks ago

rynardtspies commented 2 weeks ago

For Get-RscVmwareVm, the -Name parameter returns all VMs that partially match the specified -Name value, aligning with standard PowerShell conventions. Use the new -ExactName parameter to match the exact -Name value. e.g. Get-RscVmwareVm -Name MyExactVmName -ExactName

jakerobinson commented 2 weeks ago

Can you help me understand the purpose for introducing an additional switch for this?

Currently:

Get-RscVmwareVm -Name "Foo" will return VMs named EXACTLY "Foo". Get-RscVmwareVm -Name "*Foo*" will return VMs named CONTAINING "Foo."

Introducing this switch means that a user will have to know that they have to provide the -ExactMatch switch, which is not a pattern I've seen anywhere in PowerShell.

rynardtspies commented 2 weeks ago

Hi @jakerobinson

That is a valid and good observation.

The proposed change aligns with the pattern used in the Rubrik CDM PowerShell module:

Get-RubrikVM -Name 'Server1'
This returns details on all virtual machines named 'Server1'.

Currently, we are not fully utilizing the filtering capabilities of the RSC GQL API. We either retrieve all VMs and filter client-side, resulting in a heavy GQL response, or return an exact match. This is problematic when the user does not know the precise VM name.

To address this, we could drop the proposed -ExactName parameter and allow the user to use a wildcard (e.g., Get-RscVmwareVm -Name MyVm*). We would then detect the * in the name and apply the filter on the NAME GQL field instead of the NAME_EXACT_MATCH field.

Would this be a more acceptable solution?

jakerobinson commented 2 weeks ago

We're not filtering client-side, we're using the field REGEX or NAME_EXACT_MATCH depending on whether or not the user includes *s. Is there an advantage to using NAME over REGEX?

rynardtspies commented 2 weeks ago

So we are essentially using a blank regex?

$nameFilter.texts = $Name.Replace("*",'')

We could have just used the NAME filter instead.

I didn't realise that the * would return partial names already. I'll close this PR. Maybe we need to add a clearer example in the help text than what is currently there:

    .EXAMPLE
    # Get VMs by specifying part of a name
    Get-RscVmwareVm
    #>
jakerobinson commented 2 weeks ago

No client-side filtering whatsoever: https://github.com/rubrikinc/rubrik-powershell-sdk/blob/main/Toolkit/Public/Get-RscVmwareVm.ps1#L101-L108

Basically:

"If the string contains asterisks, use the filter field REGEX. If no asterisks, assume this is an exact name, and use the NAME_EXACT_MATCH filter."

By using the REGEX field, this opens us up in the future to allow the user to put in some regex switches, but there's currently no documentation for the allowed regex switches or format.

jakerobinson commented 2 weeks ago

Yeah, we can make it clearer if needed. A couple more examples, maybe?