CMD Session action in Desktop flow using Microsoft Power Automate

Microsoft Power Automate is a software by Microsoft for the automation of recurring tasks. It is part of the Microsoft Power Platform line of products together with products such as Power Apps and Power BI. More Details https://powerautomate.microsoft.com/en-us/

Desktop flows are the existing robotic process automation (RPA) capabilities in Power Automate and enable to automate of all repetitive desktop processes.

CMD Session actions enable you to execute the Windows commands. Open CMD session action to commence a command prompt session. To Read the output of a CMD session, we can use Read from CMD session action. To run a command, deploy the Write to CMD session action, specify a command, and select Send Enter. Close CMD session action is used to Close a previously opened CMD session.

Reading this article, you can learn how to execute the Windows commands. Using the open CMD session action, Read from the CMD session, Write to the CMD session action, and Close the CMD session action with the Desktop flow in Microsoft Power Automate.

The following important tools are required for developing Microsoft Power Automate,

  1. Windows 10/11 (Recommended)
  2. Power Automate Desktop - Download the Power Automate installer

Now we can discuss step-by-step App development.

Step 1. Open Microsoft Power Automate -> New Flow

Next, give the Flow name as PADCMD, click the Create button,

CMD Session action

After that, we are able to see the Desktop flow,

CMD Session action

Step 2. For testing CMD Session actions,

For opening a new command prompt session, add the Open CMD session action, set the Working folder parameter as <Folder Path>, Variable produced as CmdSession, and click the Save button

CMD Session action

For reading the output from the CMD session, we can use Read from CMD session action, set the CmdSession parameter as %CmdSession%, Variable produced as CmdOutput, and click the Save button.

CMD Session action

For displaying the CmdSession output, add the Display message action, set the Message box title Parameter value as DispReadCMD, Message to display Parameter value as %CmdOutput%, and click Save button.

CMD Session action

To write a new command, add the Write to CMD session action, set the CmdSession parameter as %CmdSession%, Command Parameter as Dir, Enable the Send <Enter> after the command, and click Save button.

CMD Session action

For reading the output from the CMD session, we can use Read from CMD session action, set the CmdSession parameter as %CmdSession%, Variable produced as CmdOutput2, and click the Save button.

CMD Session action

For displaying the CmdSession output, add the Display message action, set the Message box title Parameter value as DispCMDOut, Message to display Parameter value as %CmdOutput2%, and click Save button.

CMD Session action

For closing a command prompt session, add the Close CMD session action, set the CMD session parameter as %CmdSession%, and click the Save button.

CMD Session action

Now, save the PADCMD Desktop Flow,

CMD Session action

Step 3. Now we can run your PADCMD Desktop Flow in Microsoft Power Automate,

The output of the PADCMD. For opening the CMD session.

CMD Session action

After executing the Dir Command is,

CMD Session action

Summary

You have successfully tested CMD session actions in Desktop flow - PADCMD in Microsoft Power Automate.


Similar Articles