adb command for PowerShell (Windows)

Welcome to Programming Tutorial official website. Today - we are going to cover how to solve / find the solution of this error adb command for PowerShell (Windows) on this date .

I’m new to Windows. I installed adb and fastboot files (platform-tools) for Windows, and added the folder in the path variable so that I can access adb universally.

I did some research, and found that Windows is slowly shifting to PowerShell (which is good) and (I guess) will omit the legacy CMD eventually. So even the [Shift+Right click] menu shows an option to “Open PowerShell window here”. I’ve read some articles and am familiar with registry hacks to add “Open Command Prompt Here” and remove “Open PowerShell window here”, but that’s not something I would want to do, considering PowerShell is a lot more advanced than CMD.

Now, when I open PowerShell in the same folder where I’ve installed platform-tools and run the adb command, I get this and it’s successful.

.adb devices  
.adb.exe devices  

But when I open PowerShell elsewhere and run the command, it’s not successful. Why is the behavior so even when I added the adb folder to the path variable? And how can I run the command successfully universally?

During my search, I found an application which provides PowerShell ADB & Fastboot GUI – PoshADB (just wanted to share).

Please note that adb devices works just fine in cmd, universally.

A conclusion I drew from the answer below:

  • When adb files are NOT on my PATH

    • These work in the same folder where adb is installed:

      • Call by full path
        • .adb devices
        • .adb.exe devices
    • This works universally:

      • Call by full path
  • When adb files are ON my PATH

    • These work in the same folder where adb is installed:

      • Call by full path
        • .adb devices
        • .adb.exe devices
      • adb devices
    • These works universally:

      • adb devices
      • Call by full path

For my future reference- (Concisely: If it’s not on your PATH then you have to enter the full path for it to work. And if it’s on your PATH then you can just type adb devices, or mention the full path of adb)

Answer

When you use . to run a command, you’re telling PowerShell to look only in the current directory for it – the dot means “this folder,” just like in the old command processor. If the thing you’re trying to run is not in the current folder, even if it is on the PATH, that will fail. Note that the term “dot-sourcing” refers to the execution of PowerShell scripts in the current scope instead of their own, which is different from running a command from the current directory.

You can type the program’s name without . anywhere to run it if it is on your PATH. Note, though, that PowerShell will not see changes to PATH or any environment variable until you restart it. After you adjusted the environment variable and opened a new PowerShell, simply adb is sufficient to identify the program you want to run, no matter your current directory.