Equivalent of cmd's “where” in powershell












42















I can't seem to find anything about a Powershell equivalent of the where command from cmd. Should I just call it from cmd or is there something more elegant in PS?










share|improve this question













migrated from serverfault.com Nov 14 '13 at 13:20


This question came from our site for system and network administrators.



















  • Interesting reading I found sometime back on Where.exe and Get-ChildItem: blogs.technet.com/b/heyscriptingguy/archive/2010/07/24/…

    – Shawn Melton
    Nov 13 '13 at 2:16
















42















I can't seem to find anything about a Powershell equivalent of the where command from cmd. Should I just call it from cmd or is there something more elegant in PS?










share|improve this question













migrated from serverfault.com Nov 14 '13 at 13:20


This question came from our site for system and network administrators.



















  • Interesting reading I found sometime back on Where.exe and Get-ChildItem: blogs.technet.com/b/heyscriptingguy/archive/2010/07/24/…

    – Shawn Melton
    Nov 13 '13 at 2:16














42












42








42


6






I can't seem to find anything about a Powershell equivalent of the where command from cmd. Should I just call it from cmd or is there something more elegant in PS?










share|improve this question














I can't seem to find anything about a Powershell equivalent of the where command from cmd. Should I just call it from cmd or is there something more elegant in PS?







windows powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '13 at 22:02







sunnyseas











migrated from serverfault.com Nov 14 '13 at 13:20


This question came from our site for system and network administrators.









migrated from serverfault.com Nov 14 '13 at 13:20


This question came from our site for system and network administrators.















  • Interesting reading I found sometime back on Where.exe and Get-ChildItem: blogs.technet.com/b/heyscriptingguy/archive/2010/07/24/…

    – Shawn Melton
    Nov 13 '13 at 2:16



















  • Interesting reading I found sometime back on Where.exe and Get-ChildItem: blogs.technet.com/b/heyscriptingguy/archive/2010/07/24/…

    – Shawn Melton
    Nov 13 '13 at 2:16

















Interesting reading I found sometime back on Where.exe and Get-ChildItem: blogs.technet.com/b/heyscriptingguy/archive/2010/07/24/…

– Shawn Melton
Nov 13 '13 at 2:16





Interesting reading I found sometime back on Where.exe and Get-ChildItem: blogs.technet.com/b/heyscriptingguy/archive/2010/07/24/…

– Shawn Melton
Nov 13 '13 at 2:16










4 Answers
4






active

oldest

votes


















38














Use the Get-Command commandlet passing it the name of the executable. It populates the Path property of the returned object (of type ApplicationInfo) with the fully resolved path to the executable.



# ~> (get-command notepad.exe).Path
C:WINDOWSsystem32notepad.exe





share|improve this answer





















  • 8





    If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time

    – Moshe Katz
    Nov 18 '13 at 20:38











  • @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling.

    – Shawn Wang
    Jul 28 '17 at 18:07











  • And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it.

    – AFP_555
    Apr 18 '18 at 14:39



















15














If you're just looking to have the same functionality without invoking cmd, you can call where.exe from powershell, as long as C:WindowsSystem32 is in your path. The command where (without the .exe) is aliased to Where-Object, so just specify the full name.



PS C:Usersalec> where
cmdlet Where-Object at command pipeline position 1
...

PS C:Usersalec> where.exe
The syntax of this command is:

WHERE [/R dir] [/Q] [/F] [/T] pattern...





share|improve this answer

































    9














    Get-ChildItem C:SomeDir -Recurse *.dll



    That's pretty much what the old where.exe does... was there more specific functionality that you're trying to mimic?



    Edit: In response to Joshua's comment... oh, you want to search your PATH environment variables too? No problem.



    Foreach($_ In $Env:Path -Split ';')
    {
    Get-ChildItem $_ -Recurse *.dll
    }





    share|improve this answer



















    • 1





      "where" also searches the PATH as well

      – Joshua McKinnon
      Nov 13 '13 at 0:38






    • 2





      oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P

      – Synetech
      Nov 19 '13 at 2:26



















    0














    where isn't a built in cmd command. It's a standalone application (where.exe), so strictly speaking PowerShell doesn't "need a replacement".



    So why doesn't where work in PowerShell? It seems to do nothing:



    PS C:> where where
    PS C:>


    By default where is aliased to a built-in PS cmdlet.



    PS C:> get-help where

    NAME
    Where-Object
    ...
    ALIASES
    where
    ?




    Well, that's great to know, but is there a way to avoid calling where-object when trying to call where.exe?



    The answer is, yes.



    Option 1



    Call where.exe with extension. (This is a handy way to work around other aliasing and file-extension prioritisation issues.)



    PS C:> where.exe where
    C:WindowsSystem32where.exe


    Option 2



    Remove the alias.



    PS C:> Remove-Item alias:where -Force
    PS C:> where where
    C:WindowsSystem32where.exe




    Side Notes



    zdan's answer proposes using Get-Command as an alternative. Although it's a little more verbose (even when using the default gcm alias), it has richer functionality than where.exe. If used in scripting, do pay attention to the subtle differences between the two. E.g. where.exe returns all matches, whereas Get-Command returns only the first result unless you include the optional -TotalCount parameter.



    PS C:> where.exe notepad
    C:WindowsSystem32notepad.exe
    C:Windowsnotepad.exe
    PS C:> (gcm notepad).Path
    C:WINDOWSsystem32notepad.exe
    PS C:> (gcm notepad -TotalCount 5).Path
    C:WINDOWSsystem32notepad.exe
    C:WINDOWSnotepad.exe
    PS C:>


    And finally, if you remove the default where alias, you might also consider reassigning that as an alias to Get-Command. (But this would probably be of dubious benefit.)



    PS C:> Set-Alias where Get-Command
    PS C:> where notepad

    CommandType Name Version Source
    ----------- ---- ------- ------
    Application notepad.exe 10.0.15... C:WINDOWSsystem32notepad.exe


    PS C:> (where notepad).Path
    C:WINDOWSsystem32notepad.exe
    PS C:>





    share|improve this answer

























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f675837%2fequivalent-of-cmds-where-in-powershell%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown
























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      38














      Use the Get-Command commandlet passing it the name of the executable. It populates the Path property of the returned object (of type ApplicationInfo) with the fully resolved path to the executable.



      # ~> (get-command notepad.exe).Path
      C:WINDOWSsystem32notepad.exe





      share|improve this answer





















      • 8





        If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time

        – Moshe Katz
        Nov 18 '13 at 20:38











      • @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling.

        – Shawn Wang
        Jul 28 '17 at 18:07











      • And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it.

        – AFP_555
        Apr 18 '18 at 14:39
















      38














      Use the Get-Command commandlet passing it the name of the executable. It populates the Path property of the returned object (of type ApplicationInfo) with the fully resolved path to the executable.



      # ~> (get-command notepad.exe).Path
      C:WINDOWSsystem32notepad.exe





      share|improve this answer





















      • 8





        If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time

        – Moshe Katz
        Nov 18 '13 at 20:38











      • @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling.

        – Shawn Wang
        Jul 28 '17 at 18:07











      • And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it.

        – AFP_555
        Apr 18 '18 at 14:39














      38












      38








      38







      Use the Get-Command commandlet passing it the name of the executable. It populates the Path property of the returned object (of type ApplicationInfo) with the fully resolved path to the executable.



      # ~> (get-command notepad.exe).Path
      C:WINDOWSsystem32notepad.exe





      share|improve this answer















      Use the Get-Command commandlet passing it the name of the executable. It populates the Path property of the returned object (of type ApplicationInfo) with the fully resolved path to the executable.



      # ~> (get-command notepad.exe).Path
      C:WINDOWSsystem32notepad.exe






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 18 '13 at 20:43









      Moshe Katz

      2,21221532




      2,21221532










      answered Nov 14 '13 at 23:23









      zdanzdan

      2,3321516




      2,3321516








      • 8





        If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time

        – Moshe Katz
        Nov 18 '13 at 20:38











      • @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling.

        – Shawn Wang
        Jul 28 '17 at 18:07











      • And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it.

        – AFP_555
        Apr 18 '18 at 14:39














      • 8





        If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time

        – Moshe Katz
        Nov 18 '13 at 20:38











      • @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling.

        – Shawn Wang
        Jul 28 '17 at 18:07











      • And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it.

        – AFP_555
        Apr 18 '18 at 14:39








      8




      8





      If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time

      – Moshe Katz
      Nov 18 '13 at 20:38





      If you find yourself using this a lot, you can abbreviate the command as gcm instead of typing the whole Get-Command word every time

      – Moshe Katz
      Nov 18 '13 at 20:38













      @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling.

      – Shawn Wang
      Jul 28 '17 at 18:07





      @MosheKatz Thank you! gcm notepad has been working perfect for me when I just want to see which file am I calling.

      – Shawn Wang
      Jul 28 '17 at 18:07













      And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it.

      – AFP_555
      Apr 18 '18 at 14:39





      And this, boys and girls, is how you over-complicate useful things that were already right. If it isn't broken, don't fix it.

      – AFP_555
      Apr 18 '18 at 14:39













      15














      If you're just looking to have the same functionality without invoking cmd, you can call where.exe from powershell, as long as C:WindowsSystem32 is in your path. The command where (without the .exe) is aliased to Where-Object, so just specify the full name.



      PS C:Usersalec> where
      cmdlet Where-Object at command pipeline position 1
      ...

      PS C:Usersalec> where.exe
      The syntax of this command is:

      WHERE [/R dir] [/Q] [/F] [/T] pattern...





      share|improve this answer






























        15














        If you're just looking to have the same functionality without invoking cmd, you can call where.exe from powershell, as long as C:WindowsSystem32 is in your path. The command where (without the .exe) is aliased to Where-Object, so just specify the full name.



        PS C:Usersalec> where
        cmdlet Where-Object at command pipeline position 1
        ...

        PS C:Usersalec> where.exe
        The syntax of this command is:

        WHERE [/R dir] [/Q] [/F] [/T] pattern...





        share|improve this answer




























          15












          15








          15







          If you're just looking to have the same functionality without invoking cmd, you can call where.exe from powershell, as long as C:WindowsSystem32 is in your path. The command where (without the .exe) is aliased to Where-Object, so just specify the full name.



          PS C:Usersalec> where
          cmdlet Where-Object at command pipeline position 1
          ...

          PS C:Usersalec> where.exe
          The syntax of this command is:

          WHERE [/R dir] [/Q] [/F] [/T] pattern...





          share|improve this answer















          If you're just looking to have the same functionality without invoking cmd, you can call where.exe from powershell, as long as C:WindowsSystem32 is in your path. The command where (without the .exe) is aliased to Where-Object, so just specify the full name.



          PS C:Usersalec> where
          cmdlet Where-Object at command pipeline position 1
          ...

          PS C:Usersalec> where.exe
          The syntax of this command is:

          WHERE [/R dir] [/Q] [/F] [/T] pattern...






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 19 '13 at 18:25

























          answered Nov 19 '13 at 1:39









          mopsledmopsled

          27116




          27116























              9














              Get-ChildItem C:SomeDir -Recurse *.dll



              That's pretty much what the old where.exe does... was there more specific functionality that you're trying to mimic?



              Edit: In response to Joshua's comment... oh, you want to search your PATH environment variables too? No problem.



              Foreach($_ In $Env:Path -Split ';')
              {
              Get-ChildItem $_ -Recurse *.dll
              }





              share|improve this answer



















              • 1





                "where" also searches the PATH as well

                – Joshua McKinnon
                Nov 13 '13 at 0:38






              • 2





                oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P

                – Synetech
                Nov 19 '13 at 2:26
















              9














              Get-ChildItem C:SomeDir -Recurse *.dll



              That's pretty much what the old where.exe does... was there more specific functionality that you're trying to mimic?



              Edit: In response to Joshua's comment... oh, you want to search your PATH environment variables too? No problem.



              Foreach($_ In $Env:Path -Split ';')
              {
              Get-ChildItem $_ -Recurse *.dll
              }





              share|improve this answer



















              • 1





                "where" also searches the PATH as well

                – Joshua McKinnon
                Nov 13 '13 at 0:38






              • 2





                oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P

                – Synetech
                Nov 19 '13 at 2:26














              9












              9








              9







              Get-ChildItem C:SomeDir -Recurse *.dll



              That's pretty much what the old where.exe does... was there more specific functionality that you're trying to mimic?



              Edit: In response to Joshua's comment... oh, you want to search your PATH environment variables too? No problem.



              Foreach($_ In $Env:Path -Split ';')
              {
              Get-ChildItem $_ -Recurse *.dll
              }





              share|improve this answer













              Get-ChildItem C:SomeDir -Recurse *.dll



              That's pretty much what the old where.exe does... was there more specific functionality that you're trying to mimic?



              Edit: In response to Joshua's comment... oh, you want to search your PATH environment variables too? No problem.



              Foreach($_ In $Env:Path -Split ';')
              {
              Get-ChildItem $_ -Recurse *.dll
              }






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 12 '13 at 22:06









              Ryan RiesRyan Ries

              4591412




              4591412








              • 1





                "where" also searches the PATH as well

                – Joshua McKinnon
                Nov 13 '13 at 0:38






              • 2





                oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P

                – Synetech
                Nov 19 '13 at 2:26














              • 1





                "where" also searches the PATH as well

                – Joshua McKinnon
                Nov 13 '13 at 0:38






              • 2





                oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P

                – Synetech
                Nov 19 '13 at 2:26








              1




              1





              "where" also searches the PATH as well

              – Joshua McKinnon
              Nov 13 '13 at 0:38





              "where" also searches the PATH as well

              – Joshua McKinnon
              Nov 13 '13 at 0:38




              2




              2





              oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P

              – Synetech
              Nov 19 '13 at 2:26





              oh, you want to search your PATH environment variables too? Um, yes, that’s the whole point to where, otherwise you can just use dir. Der. :-P

              – Synetech
              Nov 19 '13 at 2:26











              0














              where isn't a built in cmd command. It's a standalone application (where.exe), so strictly speaking PowerShell doesn't "need a replacement".



              So why doesn't where work in PowerShell? It seems to do nothing:



              PS C:> where where
              PS C:>


              By default where is aliased to a built-in PS cmdlet.



              PS C:> get-help where

              NAME
              Where-Object
              ...
              ALIASES
              where
              ?




              Well, that's great to know, but is there a way to avoid calling where-object when trying to call where.exe?



              The answer is, yes.



              Option 1



              Call where.exe with extension. (This is a handy way to work around other aliasing and file-extension prioritisation issues.)



              PS C:> where.exe where
              C:WindowsSystem32where.exe


              Option 2



              Remove the alias.



              PS C:> Remove-Item alias:where -Force
              PS C:> where where
              C:WindowsSystem32where.exe




              Side Notes



              zdan's answer proposes using Get-Command as an alternative. Although it's a little more verbose (even when using the default gcm alias), it has richer functionality than where.exe. If used in scripting, do pay attention to the subtle differences between the two. E.g. where.exe returns all matches, whereas Get-Command returns only the first result unless you include the optional -TotalCount parameter.



              PS C:> where.exe notepad
              C:WindowsSystem32notepad.exe
              C:Windowsnotepad.exe
              PS C:> (gcm notepad).Path
              C:WINDOWSsystem32notepad.exe
              PS C:> (gcm notepad -TotalCount 5).Path
              C:WINDOWSsystem32notepad.exe
              C:WINDOWSnotepad.exe
              PS C:>


              And finally, if you remove the default where alias, you might also consider reassigning that as an alias to Get-Command. (But this would probably be of dubious benefit.)



              PS C:> Set-Alias where Get-Command
              PS C:> where notepad

              CommandType Name Version Source
              ----------- ---- ------- ------
              Application notepad.exe 10.0.15... C:WINDOWSsystem32notepad.exe


              PS C:> (where notepad).Path
              C:WINDOWSsystem32notepad.exe
              PS C:>





              share|improve this answer






























                0














                where isn't a built in cmd command. It's a standalone application (where.exe), so strictly speaking PowerShell doesn't "need a replacement".



                So why doesn't where work in PowerShell? It seems to do nothing:



                PS C:> where where
                PS C:>


                By default where is aliased to a built-in PS cmdlet.



                PS C:> get-help where

                NAME
                Where-Object
                ...
                ALIASES
                where
                ?




                Well, that's great to know, but is there a way to avoid calling where-object when trying to call where.exe?



                The answer is, yes.



                Option 1



                Call where.exe with extension. (This is a handy way to work around other aliasing and file-extension prioritisation issues.)



                PS C:> where.exe where
                C:WindowsSystem32where.exe


                Option 2



                Remove the alias.



                PS C:> Remove-Item alias:where -Force
                PS C:> where where
                C:WindowsSystem32where.exe




                Side Notes



                zdan's answer proposes using Get-Command as an alternative. Although it's a little more verbose (even when using the default gcm alias), it has richer functionality than where.exe. If used in scripting, do pay attention to the subtle differences between the two. E.g. where.exe returns all matches, whereas Get-Command returns only the first result unless you include the optional -TotalCount parameter.



                PS C:> where.exe notepad
                C:WindowsSystem32notepad.exe
                C:Windowsnotepad.exe
                PS C:> (gcm notepad).Path
                C:WINDOWSsystem32notepad.exe
                PS C:> (gcm notepad -TotalCount 5).Path
                C:WINDOWSsystem32notepad.exe
                C:WINDOWSnotepad.exe
                PS C:>


                And finally, if you remove the default where alias, you might also consider reassigning that as an alias to Get-Command. (But this would probably be of dubious benefit.)



                PS C:> Set-Alias where Get-Command
                PS C:> where notepad

                CommandType Name Version Source
                ----------- ---- ------- ------
                Application notepad.exe 10.0.15... C:WINDOWSsystem32notepad.exe


                PS C:> (where notepad).Path
                C:WINDOWSsystem32notepad.exe
                PS C:>





                share|improve this answer




























                  0












                  0








                  0







                  where isn't a built in cmd command. It's a standalone application (where.exe), so strictly speaking PowerShell doesn't "need a replacement".



                  So why doesn't where work in PowerShell? It seems to do nothing:



                  PS C:> where where
                  PS C:>


                  By default where is aliased to a built-in PS cmdlet.



                  PS C:> get-help where

                  NAME
                  Where-Object
                  ...
                  ALIASES
                  where
                  ?




                  Well, that's great to know, but is there a way to avoid calling where-object when trying to call where.exe?



                  The answer is, yes.



                  Option 1



                  Call where.exe with extension. (This is a handy way to work around other aliasing and file-extension prioritisation issues.)



                  PS C:> where.exe where
                  C:WindowsSystem32where.exe


                  Option 2



                  Remove the alias.



                  PS C:> Remove-Item alias:where -Force
                  PS C:> where where
                  C:WindowsSystem32where.exe




                  Side Notes



                  zdan's answer proposes using Get-Command as an alternative. Although it's a little more verbose (even when using the default gcm alias), it has richer functionality than where.exe. If used in scripting, do pay attention to the subtle differences between the two. E.g. where.exe returns all matches, whereas Get-Command returns only the first result unless you include the optional -TotalCount parameter.



                  PS C:> where.exe notepad
                  C:WindowsSystem32notepad.exe
                  C:Windowsnotepad.exe
                  PS C:> (gcm notepad).Path
                  C:WINDOWSsystem32notepad.exe
                  PS C:> (gcm notepad -TotalCount 5).Path
                  C:WINDOWSsystem32notepad.exe
                  C:WINDOWSnotepad.exe
                  PS C:>


                  And finally, if you remove the default where alias, you might also consider reassigning that as an alias to Get-Command. (But this would probably be of dubious benefit.)



                  PS C:> Set-Alias where Get-Command
                  PS C:> where notepad

                  CommandType Name Version Source
                  ----------- ---- ------- ------
                  Application notepad.exe 10.0.15... C:WINDOWSsystem32notepad.exe


                  PS C:> (where notepad).Path
                  C:WINDOWSsystem32notepad.exe
                  PS C:>





                  share|improve this answer















                  where isn't a built in cmd command. It's a standalone application (where.exe), so strictly speaking PowerShell doesn't "need a replacement".



                  So why doesn't where work in PowerShell? It seems to do nothing:



                  PS C:> where where
                  PS C:>


                  By default where is aliased to a built-in PS cmdlet.



                  PS C:> get-help where

                  NAME
                  Where-Object
                  ...
                  ALIASES
                  where
                  ?




                  Well, that's great to know, but is there a way to avoid calling where-object when trying to call where.exe?



                  The answer is, yes.



                  Option 1



                  Call where.exe with extension. (This is a handy way to work around other aliasing and file-extension prioritisation issues.)



                  PS C:> where.exe where
                  C:WindowsSystem32where.exe


                  Option 2



                  Remove the alias.



                  PS C:> Remove-Item alias:where -Force
                  PS C:> where where
                  C:WindowsSystem32where.exe




                  Side Notes



                  zdan's answer proposes using Get-Command as an alternative. Although it's a little more verbose (even when using the default gcm alias), it has richer functionality than where.exe. If used in scripting, do pay attention to the subtle differences between the two. E.g. where.exe returns all matches, whereas Get-Command returns only the first result unless you include the optional -TotalCount parameter.



                  PS C:> where.exe notepad
                  C:WindowsSystem32notepad.exe
                  C:Windowsnotepad.exe
                  PS C:> (gcm notepad).Path
                  C:WINDOWSsystem32notepad.exe
                  PS C:> (gcm notepad -TotalCount 5).Path
                  C:WINDOWSsystem32notepad.exe
                  C:WINDOWSnotepad.exe
                  PS C:>


                  And finally, if you remove the default where alias, you might also consider reassigning that as an alias to Get-Command. (But this would probably be of dubious benefit.)



                  PS C:> Set-Alias where Get-Command
                  PS C:> where notepad

                  CommandType Name Version Source
                  ----------- ---- ------- ------
                  Application notepad.exe 10.0.15... C:WINDOWSsystem32notepad.exe


                  PS C:> (where notepad).Path
                  C:WINDOWSsystem32notepad.exe
                  PS C:>






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 23 at 3:43

























                  answered Jan 23 at 3:07









                  DisillusionedDisillusioned

                  1033




                  1033






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f675837%2fequivalent-of-cmds-where-in-powershell%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                      Mangá

                       ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕