dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Get-DbaRegServer - Name/ServerName Support Wildcards

Open mattcargile opened this issue 4 years ago • 1 comments

Summarize Functionality

It would be convenient to write the below:

Get-DbaRegServer CMS -Name '*serv*', '*ws1'

instead of

Get-DbaRegServer CMS | Where-Object { $_.Name -like '*serv*' -or $_.Name -like '*ws1' }

Is there a command that is similiar or close to what you are looking for?

No

Technical Details

I've explored the web and found the [SupportsWildCards()] attribute which should alert the user to the new support in the help.

It didn't seem straightforward on how to implement. The current implementation uses -in and I guess to support an array of wildcards one would have to rewrite as a foreach or the like.

https://github.com/sqlcollaborative/dbatools/blob/73e3e8255778983718d9df05acb1d14d69f06af0/functions/Get-DbaRegServer.ps1#L202-L210

I also read through the Supporting Wildcard Expansion article which provided insight into System.Management.Automation.Wildcardpattern and System.Management.Automation.Wildcardoptions libraries. I assume these would provide native support for the descriptions in the Supporting Wildcard Characters in Cmdlet Parameters article. I'm not exactly sure how these would be implemented in the current build of the function.

mattcargile avatar Dec 28 '21 20:12 mattcargile

So I think I was way over thinking the usage of the library. It could just be a

  1. Check if more than One Count
  2. If only one item, then do one -like operation
  3. If more than one, then do a foreach across all the items with a -like
  4. Add the Supports Wildcard deal.

mattcargile avatar Jun 17 '22 15:06 mattcargile

So I've been looking at the Get- vs Find- commands and there seems to be a separation where you have to have the exact name of the object for get but find lets you use wildcards. Do we need a find-dbaregserver or can we use get-dbaregserver. I would really like to see all get commands accept wild cards.

mattcargile avatar Jun 20 '23 20:06 mattcargile

You are either getting the one you want or all of them with Get verb. Find is where we allow wildcard filters.

wsmelton avatar Jun 20 '23 21:06 wsmelton

You are either getting the one you want or all of them with Get verb. Find is where we allow wildcard filters.

Interesting, I do see the point logically and agree. From the core cmdlets in powershell perspective, most of them allow wild cards like get-service or get-process. And I would probably expect wildcards as a new user of dbatools from using powershell in general. So from that perspective, it could make more sense to have wildcards on all Get cmdlets. I know from an interactive perspective this would be much nicer. This is a greater question about all the get cmdlets though.

Would it make more sense in the context of dbatools to have a Find-DbaRegServer in this case since it appears we are following a stricter meaning to get versus find.

mattcargile avatar Jun 22 '23 21:06 mattcargile

I would be fine with a Find command.

The other difference between Find and Get is object size returned. Find is generally a partial object with smaller list of properties included, which comes with more performance most of the time so it can in some cases return faster than the Get (just based on how it queries). If I'm only wanting to know the name and status of an object I'd look to use Find-ThatObject, versus if I need to all there is about it, Get-ThatObject.

wsmelton avatar Jun 22 '23 21:06 wsmelton

I would be fine with a Find command.

The other difference between Find and Get is object size returned. Find is generally a partial object with smaller list of properties included, which comes with more performance most of the time so it can in some cases return faster than the Get (just based on how it queries). If I'm only wanting to know the name and status of an object I'd look to use Find-ThatObject, versus if I need to all there is about it, Get-ThatObject.

Yeah I like that more so from the definition of get-verb and what not even though core powershell doesn't always follow that. I feel like we should have a find for all the get commands?

mattcargile avatar Jun 22 '23 21:06 mattcargile