Run CMD Command in PowerShell

Wiki Hub
4 min readSep 30, 2023

--

PowerShell is used to execute the script files and carry out administrator automated tasks, while CMD is used to execute the batch files and other administrative tasks. Both command line tools are perceived to be the same, but their functionality is somehow different. Most of the identical legacy commands can be executed in both tools, but PowerShell is more capable than the command prompt.

How to run PowerShell commands from the command prompt?

To run Powershell commands from the command prompt or cmd, we need to call the PowerShell process PowerShell.exe.

Example

See the sample example,

C:\> Powershell.exe -Command “Write-Output ‘Hello world’” Hello world

Similarly, you can call any command. We will use another example to get service information

C:\> Powershell.exe -Command “Get-Service Spooler” Status Name DisplayName — — — — — — — — — — — Running Spooler Print Spooler

To run multiple commands,

C:\> Powershell.exe -Command “Stop-Service Spooler -verbose -passthru; Start-Service Spooler -verbose -passthru”

Output

VERBOSE: Performing the operation “Stop-Service” on target “Print Spooler (Spooler)”. Status Name DisplayName — — — — — — — — — — — Stopped Spooler Print Spooler VERBOSE: Performing the operation “Start-Service” on target “Print Spooler (Spooler)”. Running Spooler Print Spooler

The above command is similar to,

C:\> Powershell.exe Invoke-Command -scriptblock { “Stop-Service Spooler -verbose — passthru; Start-Service Spooler -verbose -passthru” }

PowerShell run as Administrator

There are five easy methods to run a PowerShell as an administrator in Windows Operating system:

• Run PowerShell as an Administrator using the run window (for all versions of Windows).

• Run PowerShell as an Administrator using Cortana Search bar (for Windows 10).

• Run PowerShell as an Administrator from the command prompt.

• Run PowerShell as an Administrator from task manager.

• Run PowerShell as an Administrator from the Start menu.

1. Run PowerShell as an Administrator using the run window

Step 1: Press the Windows + R keys together to bring up the Run dialog box.

Step 2: Type the PowerShell in the box and click OK button. A normal Window PowerShell will launch as a current user.

Step 3: Type the command start-process PowerShell -verb runas and press “enter” key.

Step 4: The above command will bring up an elevated Windows PowerShell as an administrator.

2. Run PowerShell as an Administrator using Cortana Search bar (for Windows 10)

Step 1: Windows 10 comes with a Cortana search field in the taskbar. Type the PowerShell in the search field.

Step 2: Right-click on the Windows PowerShell and then select the run as administrator. It will open a Windows PowerShell which will run as an administrator.

3. Run PowerShell as an Administrator from Command prompt

Step 1: Open the Command Prompt, and type the PowerShell as a command, then press Enter key.

Step 2: Now, the command prompt will turn to Windows PowerShell.

Step 3: Type the command start-process PowerShell -verb runas and press “enter” key.

Step 4: It will bring up an elevated Windows PowerShell as an administrator.

4. Run PowerShell as an Administrator from Task Manager

Step 1: Press the ctrl + shift + Esc buttons together in windows 10 or 8 to open the task manager. By default, it shows fewer details, click on .....

Read full details

--

--