- 1 year ago
How to run a CMD task inside of PowerShell?
To run a CMD task inside of PowerShell, you can use the Start-Process
cmdlet or invoke CMD commands using the &
(call operator) or Invoke-Expression
cmdlet. Here are a few examples:
Using
Start-Process
:powershellStart-Process cmd.exe -ArgumentList '/c your_cmd_command' -NoNewWindow -Wait
Replace
'your_cmd_command'
with the actual CMD command you want to execute. The/c
option tells CMD to execute the command and then terminate.Using the call operator
&
:powershell& cmd.exe /c your_cmd_command
Replace
'your_cmd_command'
with the desired CMD command.Using
Invoke-Expression
:powershellInvoke-Expression 'cmd.exe /c your_cmd_command'
Replace
'your_cmd_command'
with the CMD command you want to execute.
In each of these examples, the CMD command is executed within a PowerShell session. The /c
option is used to execute the command and then terminate the CMD session.
Choose the method that best suits your needs based on the specific requirements of your CMD task.