Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

rynardtspies
Copy link
Collaborator

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
Copy link
Collaborator

jakerobinson commented Aug 28, 2024

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@rynardtspies rynardtspies deleted the fix_get-vmware-vm_name_filter branch August 28, 2024 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants