Powershell

Run PowerShell Command From Command Prompt

PowerShell is a configuration management and task automation administrative Windows utility. It is a command-line tool and it is also associated with a scripting language. This tool can perform all the elevated tasks on the system. The “Command Prompt” is another Windows administrator tool that also mimics the functionality of PowerShell. PowerShell and its commands can be executed in “Command Prompt”.

This article will guide about running a PowerShell command from CMD.

Run PowerShell Command From Command Prompt

The commands of PowerShell can be executed from the Command Prompt by applying the approaches given below:

Method 1: Run PowerShell Command From Command Prompt by Enabling PowerShell Console

The PowerShell commands can be executed in the command prompt by enabling its interface by simply running the “PowerShell” command in CMD.

Step 1: Enable PowerShell Console in Command Prompt

First, write and execute the below cmdlet to enable the PowerShell interface in CMD:

powershell

Step 2: Execute a PowerShell Command From Command Prompt

After enabling PowerShell in CMD, let’s execute the command:

Get-ChildItem C:\Doc

In accordance with the above code:

First, add the “Get-ChildItem” cmdlet that gets the one or more items from a specified location and define the path to get items from it:

Step 3: Exit From PowerShell Console

In order to return to the CMD or to take an exit from the PowerShell interface, execute the “exit” command:

exit

Method 2: Run PowerShell Command From Command Prompt By Adding “PowerShell” At the Start of Each Command

The PowerShell commands can be executed in CMD by specifying the “PowerShell” keyword at the start of the cmdlet. Demonstrations of the stated concept is given below.

Example 1: Run a PowerShell String in Command Prompt

This example will run a PowerShell command in the Command Prompt:

powershell write-output "Hello"

Here:
First, specify the “powershell” keyword to enable PowerShell in CMD.
Then, add the “write-output” cmdlet and add the string to be displayed:

Example 2: Run the PowerShell “Get-Date” Command in Command Prompt

This instance will execute the “Get-Date” cmdlet of PowerShell from CMD:

powershell Get-Date

According to the stated code above:

First, define a “powershell” keyword and then add the “Get-Date” command:

That was all about running the PowerShell command from the command prompt.

Conclusion

The PowerShell commands can be executed in the command prompt using two methods. The first method is to enable the PowerShell interface in CMD by executing the “PowerShell” cmdlet. After that, the cmdlets of PowerShell can easily be executed in CMD. The other method is to add the “PowerShell” keyword at the start of every command. This write-up has discussed multiple methods to run PowerShell commands from the command prompt.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.