Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the proper PowerShell verb/pattern for get-or-create?

I want to create a few PowerShell functions that create an item, or return existing item if it is already there. E.g. database login, folder, etc.

What is a proper verb for this? There is no Ensure in Approved Verbs, and I am not sure what else would be applicable. I considered New-X -IfExists ReturnExisting but I would prefer to follow a common pattern instead of inventing my own.

Are there any built-in PowerShell commandlets that do get-or-create so that I can copy the approach?

like image 774
Andrey Shchekin Avatar asked Sep 30 '22 14:09

Andrey Shchekin


1 Answers

Per the approved verb listing:

New vs. Set
The New verb is used to create a new resource. The Set verb is used to modify an existing resource, optionally creating the resource if it does not exist, such as the Set-Variable cmdlet.

like image 141
TheMadTechnician Avatar answered Oct 05 '22 06:10

TheMadTechnician