Feature Request / enable the creation of alias with cmdlet and its params together
See original GitHub issueSummary of the new feature/enhancement
Currenly, we can only create alias to a cmdlet name only, it would be nice to be able to create alias to the cmdlet and with its params also.
The workaround that I could find till now is to create in advance a new custom cmdlet (via function{}) which calls the target cmdlet with the expected params, and then create an alias that points to this new cmdlet.
# The workaround by creating a new cmdlet,
# ok for complexe functions,
# but not cool for calling just a cmdlet with params in one line.
function Out-StringWithStream {
Out-String -Stream
}
Set-Alias oss Out-StringWithStream
Proposed technical implementation details (optional)
Set-Alias oss Out-String -Stream
# or with ScriptBlock
Set-Alias oss {Out-String -Stream}
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Set-Alias (Microsoft.PowerShell.Utility)
The Set-Alias cmdlet creates an alias to the function in the current PowerShell session. The Name parameter specifies the alias's name, Go ....
Read more >PowerShell - Is there a way to create a sort of 'alias' that ...
I recently created a PowerShell script to automate and test PowerCLI scripts before running them on vCenters/ESXi hosts. At the moment, I use...
Read more >What is PowerShell and How to Use It: The Ultimate Tutorial
This comprehensive guide explains Windows PowerShell's key uses and features. Learn more about the flexible command-line interface and automation tool.
Read more >Designing Professional Parameters - powershell.one
Parameters are a way for the caller to submit information to code. They are a fundamental feature of PowerShell scriptblocks: a param() ...
Read more >Create or update alias API | Elasticsearch Guide [8.9]
Path parametersedit · <alias>: (Required, string) Alias to update. If the alias doesn't exist, the request creates it. Index alias names support date...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My old pspx module makes this easier. I could refresh that for PowerShell v.Current. It’s one of those things where I felt like a rather extreme propeller head and wondered if anyone was actually using the functionality it provided, but it would allow for something like this:
I don’t know if you can actually get the code for that module from that link anymore, but I have it local, and started refreshing it a little while ago. I would need to think about how I would do the same thing if I were to design it for PowerShell today.
Even with that though, there is definitely something to be said about associating an identifier (like an alias, but I think functions are better for this) with a command plus a default set of parameter values, and having PowerShell know exactly what to do. It’s quite a simple concept, really. My
New-ProxyFunction
command could do much, much more than that, but the simple case would be quite useful.What if the identifier was not an alias? What if we added a
New-Function
command that had one parameter set to simply define a function (like you can withNew-Item
, today, taking a name and a script block), and another parameter set that accepts a name, the name of a command you want to proxy, and a hashtable of parameters you want passed in by default. I wouldn’t call thatNew-ProxyFunction
– the fact that it creates a proxy is a little beside the point, and the name shouldn’t add complexity to what it does IMHO. I would just call itNew-Function
, and let the-CommandToInvoke
parameter indicate that it’s actually proxying something. That would allow for an even simpler syntax than whatpspx
provided, like this:Since you can create proxy cmdlets, I wonder if I should just do that but create proxy cmdlets instead for better performance than proxy functions. 🤔
@iSazonov I disagree with the resolution of this issue. Answering a request by saying “just go do this really complicated thing” (proxy commands are not trivial) is not an answer. At a minimum, it should be left open to see if others have similar interest or to continue the discussion. Having it marked as closed and answered signals that there isn’t a discussion to be had here.