Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / Run an External Program or Command with Arguments from PowerShell

March 26, 2026

Run an External Program or Command with Arguments from PowerShell

Sometimes, you may need to execute an external command, command-line tool, or EXE program from a terminal or PowerShell script. This post explores commonly used methods for running external programs and console tools from PowerShell, including passing several arguments with spaces and quotes, and capturing program output in scripts.

To run standard Windows command-line tools (like ping , tracert , diskpart, etc) from the PowerShell console, simply specify the tool name followed by its required arguments.

ping woshub.com

Run command from PowerShell

However, this will work only for commands whose paths are contained in the PATH environment variable. This means that system tools and commands in the %WINDIR% and %WINDIR%\System32 directories can be run from PowerShell without specifying an absolute path or additional arguments.

(Get-ChildItem env:Path).value -split ";"

List env varaible PATH

If you attempt to run an arbitrary executable from the current directory (e.g., after navigating with cd c:\folder), invoking it by name will result in an error:

psexec: The term 'psexec' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Suggestion [3,General]: The command "psexec" was not found, but does exist in the current location. PowerShell does not load commands from the current location by default (see ''Get-Help about_Command_Precedence''). If you trust this command, run the following command instead:

PowerShell error: the term is not recognized as a name of a cmdlet, function, script file, or executable program. The command was not found, but does exist in the current location. PowerShell does not load commands from the current location by default

By default, PowerShell doesn’t load commands (programs) from the current directory unless that directory is added to the PATH system variable. To run an application from the current folder, prepend .\ (period followed by backslash) to the command name. For example:

.\psexec.exe

run program from current dir in powershell

Or, to run the command or application, specify the full path to its executable.

C:\PSTools\PsLoggedon64.exe

use full file path

The call operator (&) can also be used to execute external commands and programs from within a PowerShell script. The following syntax is used

& <Command-String> <Arguments>

For example, to run a command-line tool and output the result to the PS console:

& 'C:\Tools\handle64.exe'

To pass multiple arguments to a program (tool) via the call operator (&) in PowerShell, use the following syntax:

$exe = "C:\PSTools\handle64.exe"
$arguments = '-u', '12345', '-nobanner'
& $exe $arguments

run external tool or command with arguments from powershell

You can call the CMD.EXE shell to invoke programs directly from the PowerShell prompt. For example:

cmd.exe /c "echo Make CMD great again"

or:

cmd.exe /c "C:\PSTools\Pslist.exe msedge"

This command launches a new cmd.exe instance, runs the command specified by the /c argument, and prints the result to the console.

running command via cmd.exe with /c

To launch an arbitrary application with command-line arguments from PowerShell, use the Start-Process cmdlet.

Start-Process -FilePath 'C:\Program Files\CORP\app.exe' -ArgumentList 'DaemonMode' -NoNewWindow -Wait

The Start-Process cmdlet doesn’t return output by default, but you can add the -PassThru parameter to return a process object for a running process:

$result_process = Start-Process ping -ArgumentList "-n 1 woshub.com" -NoNewWindow -Wait -PassThru

After this, you can access information about the process, including the PID, exit code, etc.

$result_process.ExitCode

To execute an external command (program) from PowerShell, capture its output, and process the results within a script, you can use the Invoke-Expression or Invoke-Command cmdlets:

$result=Invoke-Expression -Command "cmd.exe /c C:\PSTools\handle64.exe 12345 -u -nobanner"

$result=Invoke-Command -ScriptBlock {"C:\PSTools\handle64.exe 12345 -u -nobanner"}

Invoke-Expression in PowerShell

The Invoke-Command cmdlet is commonly used to execute commands on remote computers via PowerShell Remoting (WinRM).
0 comment
1
Facebook Twitter Google + Pinterest
PowerShellQuestions and AnswersWindows 11
previous post
Monitor Windows Log Files in Real Time with PowerShell

Related Reading

Uninstalling Windows Updates via CMD/PowerShell

March 10, 2026

Pin and Unpin Apps to Taskbar in Windows...

March 10, 2026

Automate Software and Settings Deployment with WinGet Configure...

November 20, 2025

Enable/Disable Random Hardware (MAC) Address for Wi-Fi on...

November 20, 2025

How to Pause (Delay) Update Installation on Windows...

April 11, 2025

Run Elevated Commands with Sudo on Windows 11

August 21, 2025

Monitor Windows Log Files in Real Time with...

March 17, 2026

How to Disable PowerShell on Windows for Non-Admin...

November 27, 2025

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Load and Initialize Network Drivers in Windows PE or Recovery Environment

    February 25, 2026
  • How to Set a Custom Drive Icon in Windows

    February 17, 2026
  • Managing Per-User Services in Windows

    February 11, 2026
  • Change Default OU for New Computers and Users in AD

    February 2, 2026
  • Where Windows Stores Certificates and Private Keys

    January 22, 2026
  • How to Remove Old (Unused) PowerShell Modules

    January 12, 2026
  • How to Move (Migrate) Windows Shares to a New File Server

    December 24, 2025
  • Using KDC (Kerberos) Proxy in AD for Remote Access

    December 23, 2025
  • Windows: Create (Install) a Service Manually

    December 16, 2025
  • Windows: Auto Switch to Strongest Wi-Fi Network

    December 10, 2025

Follow us

  • Facebook
  • Twitter
  • Youtube
  • Telegram
Popular Posts
  • Run Elevated Commands with Sudo on Windows 11
  • Fix: Slow Startup of PowerShell Console and Scripts
  • Automate Software and Settings Deployment with WinGet Configure (DSC)
  • Enable/Disable Random Hardware (MAC) Address for Wi-Fi on Windows
  • How to Pause (Delay) Update Installation on Windows 11 and 10
  • Pin and Unpin Apps to Taskbar in Windows 11 via PowerShell
  • How to Hide (Block) a Specific Windows Update
Footer Logo

@2014 - 2026 - Windows OS Hub. All about operating systems for sysadmins


Back To Top