Forum Discussion

bmidhun's avatar
bmidhun
Frequent Visitor
1 year ago
Solved

Request for Guidance on Programmatically Generating PBIP Folder Structure Using C# or PowerShell

Hi Team

 

We would like to request support or guidance on replicating the exact folder structure of a PBIP file programmatically, as outlined below:

 

Report
  .Report/.pbi
  .Report/StaticResources
  All platform files, including definition.pbir and report.json

SemanticModel
  .pbi
  definition

 

Our goal is to understand whether it is feasible to dynamically generate this complete PBIP folder structure using C# or PowerShell.

 

Any advice, suggestions, or relevant references from the community would be greatly appreciated.

  • Hi @bmidhun  ,

     

    we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

    If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

    Regards,

    Chaithanya.

8 Replies

  • v-kathullac's avatar
    v-kathullac
    Community Support

    Hi @bmidhun  ,

     

    we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

    If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

    Regards,

    Chaithanya.

  • Bhavnish's avatar
    Bhavnish
    Frequent Visitor

    goes outside the scope of power Bi

    Staying within the scope of power Bi , if you are trying to replicate the structure for multiple members just for connection purpose , using a PBIDS format would allow you to do that

     

    As per copilot you can use the following commands :

    1. Using PowerShell
    PowerShell's directory and file management capabilities make it a good choice for this task. Here's a basic outline of the script:

    # Define the root folder
    $rootPath = "C:\PBIP_FolderStructure"

    # Create Report folder structure
    New-Item -ItemType Directory -Path "$rootPath\Report\.Report"
    New-Item -ItemType Directory -Path "$rootPath\Report\.Report\StaticResources"
    New-Item -ItemType File -Path "$rootPath\Report\.Report\.pbi"
    New-Item -ItemType File -Path "$rootPath\Report\definition.pbir"
    New-Item -ItemType File -Path "$rootPath\Report\report.json"

    # Create SemanticModel folder structure
    New-Item -ItemType Directory -Path "$rootPath\SemanticModel"
    New-Item -ItemType File -Path "$rootPath\SemanticModel\.pbi"
    New-Item -ItemType File -Path "$rootPath\SemanticModel\definition"

     

    2. Using C#
    C# gives you more flexibility and allows integration into larger applications. Below is an example:

    using System;
    using System.IO;

    class Program
    {
    static void Main()
    {
    string rootPath = @"C:\PBIP_FolderStructure";

    // Create Report folder structure
    Directory.CreateDirectory(Path.Combine(rootPath, @"Report\.Report\StaticResources"));
    File.Create(Path.Combine(rootPath, @"Report\.Report\.pbi")).Dispose();
    File.Create(Path.Combine(rootPath, @"Report\definition.pbir")).Dispose();
    File.Create(Path.Combine(rootPath, @"Report\report.json")).Dispose();

    // Create SemanticModel folder structure
    Directory.CreateDirectory(Path.Combine(rootPath, "SemanticModel"));
    File.Create(Path.Combine(rootPath, @"SemanticModel\.pbi")).Dispose();
    File.Create(Path.Combine(rootPath, "SemanticModel/definition")).Dispose();

    Console.WriteLine("PBIP folder structure created successfully!");
    }
    }


    Compile and run this C# program, and it will generate the desired folder structure and files.

  • bmidhun 

    Here’s a full PowerShell script to generate this folder structure:

    # Set the root folder where you want to create the PBIP structure
    $rootPath = "C:\PBIPSample"

    # Define all the folder paths
    $folders = @(
    "$rootPath\Report\.pbi",
    "$rootPath\Report\StaticResources",
    "$rootPath\SemanticModel\.pbi"
    )

    # Define the file paths
    $files = @(
    "$rootPath\Report\definition.pbir",
    "$rootPath\Report\report.json",
    "$rootPath\SemanticModel\definition"
    )

    # Create all folders
    foreach ($folder in $folders) {
    if (!(Test-Path -Path $folder)) {
    New-Item -ItemType Directory -Path $folder -Force
    }
    }

    # Create empty files
    foreach ($file in $files) {
    if (!(Test-Path -Path $file)) {
    New-Item -ItemType File -Path $file -Force
    }
    }

    Write-Host "PBIP structure created successfully at $rootPath!"

    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!



  • bmidhun's avatar
    bmidhun
    Frequent Visitor

    Thanks MFelix johnbasha33 Bhavnish  for your reply. But as per my requirement including folder structure i need to generate all the necessary files which completes the PowerBI Project file (PBIP).

    Kindly let me know if there is any code or link which can help me on the same.

  • bmidhun's avatar
    bmidhun
    Frequent Visitor

    Kindly let me know if anyone have any idea on the above topic

    • v-kathullac's avatar
      v-kathullac
      Community Support

      Hi bmidhun ,

      Thank you for reaching out to Microsoft Fabric Community Forum.

      can you try the below code in powershell .

      # Define the root directory for the PBIP project
      $rootPath = "C:\PowerBIProject"
      
      # Create the main folders
      $reportPath = Join-Path $rootPath "Report"
      $semanticModelPath = Join-Path $rootPath "SemanticModel"
      $reportFolderPath = Join-Path $reportPath ".Report"
      $staticResourcesPath = Join-Path $reportPath "StaticResources"
      
      # Create the directories
      New-Item -ItemType Directory -Path $reportFolderPath -Force
      New-Item -ItemType Directory -Path $staticResourcesPath -Force
      New-Item -ItemType Directory -Path $semanticModelPath -Force
      
      # Create sample .pbi files and other platform files
      New-Item -ItemType File -Path (Join-Path $reportFolderPath ".pbi") -Force
      New-Item -ItemType File -Path (Join-Path $staticResourcesPath "placeholder.txt") -Force
      New-Item -ItemType File -Path (Join-Path $reportPath "definition.pbir") -Force
      New-Item -ItemType File -Path (Join-Path $reportPath "report.json") -Force
      New-Item -ItemType File -Path (Join-Path $semanticModelPath ".pbi") -Force
      New-Item -ItemType File -Path (Join-Path $semanticModelPath "definition") -Force
      
      # Output success message
      Write-Host "PBIP folder structure has been created at $rootPath"
      

      Regards,

      Chaithanya.

       

       

  • v-kathullac's avatar
    v-kathullac
    Community Support

    Hi bmidhun  ,

     

    we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

    If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

    Regards,

    Chaithanya.