Wednesday, 23 April 2025

List All Power Automate Cloud Flows Programmatically

Leave a Comment

When a cloud flow is part of a solution in Power Automate, it gets stored in Microsoft Dataverse as a type of record in the workflow table.

Using either

  • Dataverse SDK for .NET: for C# developers, or
  • Dataverse Web API: for RESTful access via HTTP,
Use the Dataverse SDK in C#/.NET

Step 1. Create a new .NET console app project. For this project, we are using Visual Studio 2022 and targeting .NET 6.

Step 2. In Solution Explorer, right-click the project you created and select Manage NuGet Packages... in the context menu.


Step 3.
 Browse for the latest version of Microsoft.PowerPlatform.Dataverse.Client NuGet package and install it.

Step 4. Add the below code in program.cs file

using Microsoft.Crm.Sdk.Messages;
using Microsoft.PowerPlatform.Dataverse.Client;
using Microsoft.Xrm.Sdk;

class Program
{
   // TODO Enter your Dataverse environment's URL and logon info.
   static string url = "https://yourorg.crm.dynamics.com";  // Replace your Power Platform Environment Url from https://admin.powerplatform.microsoft.com
   static string userName = "[email protected]"; // Power Platform User Login Id
   static string password = "yourPassword"; // Power Platform user password

   // This service connection string uses the info provided above.
   // The AppId and RedirectUri are provided for sample code testing.
   static string connectionString = $@"AuthType=OAuth;Url={url};UserName={userName};Password= {password};AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Auto;RequireNewInstance=True";

   static void Main()
   {
    //ServiceClient implements IOrganizationService interface
    IOrganizationService service = new ServiceClient(connectionString);
    OutputActiveFlows(service);

    // Pause the console so it does not close.
    Console.WriteLine("Press the <Enter> key to exit.");
    Console.ReadLine();
   }
   public static void OutputActiveFlows(IOrganizationService service)
   {
     var query = new QueryExpression("workflow")
     {
         ColumnSet = new ColumnSet("category",
                                   "createdby",
                                   "createdon",
                                   "description",
                                   "ismanaged",
                                   "modifiedby",
                                   "modifiedon",
                                   "name",
                                   "ownerid",
                                   "statecode",
                                   "type",
                                   "workflowid",
                                   "workflowidunique"),
         Criteria = new FilterExpression(LogicalOperator.And)
         {
             Conditions =
             {
              { new ConditionExpression("category",ConditionOperator.Equal,5) }, // Cloud Flow
              { new ConditionExpression("statecode",ConditionOperator.Equal,1) } // Active
             }
         },
         //TopCount = 1 // Limit to one record
     };

     EntityCollection workflows = service.RetrieveMultiple(query);

     //Entity workflow = workflows.Entities.FirstOrDefault();
     foreach (var workflow in workflows.Entities)
     {
         Console.WriteLine($"category: {workflow.FormattedValues["category"]}");
         Console.WriteLine($"createdby: {workflow.FormattedValues["createdby"]}");
         Console.WriteLine($"createdon: {workflow.FormattedValues["createdon"]}");
         // Description may be null
         Console.WriteLine($"description: {workflow.GetAttributeValue<string>("description")}");
         Console.WriteLine($"ismanaged: {workflow.FormattedValues["ismanaged"]}");
         Console.WriteLine($"modifiedby: {workflow.FormattedValues["modifiedby"]}");
         Console.WriteLine($"modifiedon: {workflow.FormattedValues["modifiedon"]}");
         Console.WriteLine($"name: {workflow["name"]}");
         Console.WriteLine($"ownerid: {workflow.FormattedValues["ownerid"]}");
         Console.WriteLine($"statecode: {workflow.FormattedValues["statecode"]}");
         Console.WriteLine($"type: {workflow.FormattedValues["type"]}");
         Console.WriteLine($"workflowid: {workflow["workflowid"]}");
         Console.WriteLine($"workflowidunique: {workflow["workflowidunique"]}");
     }

 }
}

Sample Output

category: Modern Flow
createdby: SYSTEM
createdon: 5/20/2020 9:37 PM
description:
ismanaged: Unmanaged
modifiedby: Kiana Anderson
modifiedon: 5/6/2023 3:37 AM
name: When an account is updated -> Create a new record
ownerid: Monica Thomson
statecode: Activated
type: Definition
workflowid: d9e875bf-1c9b-ea11-a811-000d3a122b89
workflowidunique: c17af45c-10a1-43ca-b816-d9cc352718cf

Note. Only flows inside Solutions are accessible this way—not personal flows in the "My Flows" section.

Conclusion

Managing Power Automate cloud flows through code gives developers and IT teams powerful tools to automate, secure, and scale their operations. Whether you prefer the structured approach of the .NET SDK or the flexibility of REST APIs, you can perform critical tasks—like listing, deleting, sharing, and exporting flows—without ever opening the Power Automate UI.

We will see Create, Update, and Delete operations for cloud flows in my next Article.

ASP.NET Core 9.0 Hosting Recommendation

One of the most important things when choosing a good ASP.NET Core 9.0 hosting is the feature and reliability. HostForLIFE is the leading provider of Windows hosting and affordable ASP.NET Core, their servers are optimized for PHP web applications. The performance and the uptime of the hosting service are excellent and the features of the web hosting plan are even greater than what many hosting providers ask you to pay for. 

At HostForLIFE.eu, customers can also experience fast ASP.NET Core hosting. The company invested a lot of money to ensure the best and fastest performance of the datacenters, servers, network and other facilities. Its datacenters are equipped with the top equipments like cooling system, fire detection, high speed Internet connection, and so on. That is why HostForLIFEASP.NET guarantees 99.9% uptime for ASP.NET Core. And the engineers do regular maintenance and monitoring works to assure its Orchard hosting are security and always up.

0 comments:

Post a Comment