A question about PowerShell's Alias function


  1. Posts : 49
    Windows 7 Professional x64
       #1

    A question about PowerShell's Alias function


    I am trying to set up a powershell resource file and add a bunch of aliases to common unix programs and I am trying to find out if I can alias function flags some how as well.

    For example the string regex function Select-String looks alot like grep in the *nix world and I know I can alias Select-String to grep if I wanted to. However the flags are completely different so I am wondering is their a way to alias flags as well. For example going back to Select-String, Select-String -NotMatch would be grep -v. So to boil down my question can I make an alias to the flags of an alias.
    eg:
    Select-String -Case-Sensitive -> grep
    Select-String -> grep -i
    Select-String -NotMatch -> grep -v
    etc ...
      My Computer


  2. Posts : 721
    Windows 10, Windows 8.1 Pro, Windows 7 Professional, OS X El Capitan
       #2

    Sorry, Alpha, not possible.

    See here:
    You can create an alias for a cmdlet, but you cannot create an alias for a command with parameters and values. For example, you can create an alias for Set-Location, but you cannot create an alias for "Set-Location C:\Windows\System32".
    Alpha90 said:
    So to boil down my question can I make an alias to the flags of an alias.
    You're going to have to create a wrapper function for that.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 09:56.
Find Us