Forum Discussion
Request for Guidance on Programmatically Generating PBIP Folder Structure Using C# or PowerShell
- 1 year ago
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.
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.