3

I have a question about how PS abbreviates various commands, particularly when initializing a PS session.

Let's assume we're starting at a Windows DOS Prompt:

C:\> powershell -exec bypass

I seem to notice that you can also type the following, and it appears as though it still runs:

C:\> powershell -execution bypass

C:\> powershell -exec by

C:\> powershell -exec b

Is it the case that PowerShell will "guess" at the command a user is trying to run if what's typed is unique enough to match known valid commands/options/flags/parameters? If there's any literature that explains what's happening here, that'd be extremely helpful. Thank you!

3
  • I don't know of any official documentation off-hand, but as with many CLI systems, the switches you've typed simply need to unambiguous, as it appears (and applies to other elements too, but I'm not sure which, off-hand). Here's an SO thread that seems to have some on-point answers. May 18, 2016 at 19:53
  • 1
    (Also worth noting that you probably shouldn't do this... with tab completion in PowerShell 3.0+, that's the better approach. Same reduction in typing, but generates more readable code.) May 18, 2016 at 20:04
  • @HoplessN00b exactly the two reasons I was going to argue, the aliases are handy when coming from a unix background when you keep typing ls instead of dir, and I think that's there main 'usage' otherwise don't intentionally use them
    – Sum1sAdmin
    May 18, 2016 at 20:40

1 Answer 1

7

Powershell will allow abbreviated parameter names until the parameter is no longer unambiguous. That's been the case since 1.0. You can do this in in scripts as well but it's not the recommended practice in scripts since a later version of the cmdlet may no longer have the abbreviation be unambiguous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.