Skip to content
Rishan Solutions
Rishan Solutions
  • PowerApps
  • SharePoint online
    • Uncategorized
    • Uncategorized
  • PowerAutomate
Rishan Solutions
Latest Posts
  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025 June 24, 2025
  • Recursive Queries in T-SQL May 7, 2025
  • Generating Test Data with CROSS JOIN May 7, 2025
  • Working with Hierarchical Data May 7, 2025
  • Using TRY_CAST vs CAST May 7, 2025
  • Dynamic SQL Execution with sp_executesql May 7, 2025

Exporting Dataverse Table Schema using PowerShell

Posted on March 24, 2025March 24, 2025 by Rishan Solutions

Loading

Microsoft Dataverse provides a structured way to manage business data within Power Platform. If you need to back up or migrate your table schema (metadata), you can use PowerShell to export it. This guide explains how to extract the Dataverse table schema using PowerShell.


Step 1: Prerequisites

1. Required Permissions

  • You must have the System Administrator or Power Platform Admin role in Dataverse.
  • The Microsoft Dataverse API should be enabled for your environment.

2. Install and Import PowerShell Modules

To interact with Dataverse, install and import the required PowerShell modules.

# Install Power Platform Administration module
Install-Module -Name Microsoft.PowerPlatform.Administration -Scope CurrentUser -Force

# Install Dataverse Client module
Install-Module -Name Microsoft.PowerPlatform.Cds.Client -Scope CurrentUser -Force

# Import modules
Import-Module Microsoft.PowerPlatform.Administration
Import-Module Microsoft.PowerPlatform.Cds.Client

Step 2: Connect to Dataverse

Option 1: Interactive Login (Prompt for Credentials)

# Connect to Dataverse interactively
$connection = Connect-CdsService -ConnectionString "AuthType=OAuth;Url=https://yourorg.crm.dynamics.com;Prompt=Login"

A sign-in window will appear, prompting you to log in with your Microsoft 365 admin credentials.

Option 2: Using Service Principal (App Registration)

For automated scripts, use an Azure AD App Registration.

# Define connection details
$clientId = "your-app-client-id"
$clientSecret = "your-app-client-secret"
$tenantId = "your-tenant-id"
$orgUrl = "https://yourorg.crm.dynamics.com"

# Create authentication context
$secureSecret = ConvertTo-SecureString $clientSecret -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($clientId, $secureSecret)

# Connect to Dataverse
$connection = Connect-CdsService -Url $orgUrl -ClientId $clientId -ClientSecret $secureSecret -TenantId $tenantId

Step 3: Retrieve Table Schema from Dataverse

To export the schema, retrieve the metadata of a specific table.

# Define the table name
$tableName = "new_CustomerData" # Replace with your table’s logical name

# Retrieve table metadata
$tableMetadata = Get-CdsEntity -Connection $connection -EntityLogicalName $tableName

# Display table schema
$tableMetadata | Select-Object LogicalName, DisplayName, Description, OwnershipType

Step 4: Retrieve Column Metadata

Extract details about all columns (attributes) of a specific table.

# Retrieve all columns for the specified table
$columns = Get-CdsTableColumn -Connection $connection -EntityLogicalName $tableName

# Display columns
$columns | Select-Object LogicalName, DisplayName, AttributeType, IsRequired

Step 5: Export Schema to a CSV File

1. Export Table Schema

# Define file path
$schemaFilePath = "C:\Dataverse_Schema\TableSchema.csv"

# Export table metadata to CSV
$tableMetadata | Select-Object LogicalName, DisplayName, Description, OwnershipType | Export-Csv -Path $schemaFilePath -NoTypeInformation

Write-Host "Table schema exported successfully to $schemaFilePath"

2. Export Column Schema

# Define file path for columns
$columnFilePath = "C:\Dataverse_Schema\ColumnSchema.csv"

# Export column metadata to CSV
$columns | Select-Object LogicalName, DisplayName, AttributeType, IsRequired | Export-Csv -Path $columnFilePath -NoTypeInformation

Write-Host "Column schema exported successfully to $columnFilePath"

Step 6: Export Schema to JSON

You can also export schema in JSON format for use in other applications.

# Define file path
$jsonFilePath = "C:\Dataverse_Schema\Schema.json"

# Convert table and column metadata to JSON
$schemaData = @{
Table = $tableMetadata | Select-Object LogicalName, DisplayName, Description, OwnershipType
Columns = $columns | Select-Object LogicalName, DisplayName, AttributeType, IsRequired
}

# Export JSON
$schemaData | ConvertTo-Json -Depth 2 | Set-Content -Path $jsonFilePath

Write-Host "Schema exported successfully to $jsonFilePath"

Step 7: Export All Tables and Columns in Dataverse

If you need to extract all tables and columns in your Dataverse environment, run:

# Retrieve all tables
$allTables = Get-CdsEntity -Connection $connection

# Export all tables to CSV
$allTables | Select-Object LogicalName, DisplayName, Description, OwnershipType | Export-Csv -Path "C:\Dataverse_Schema\AllTables.csv" -NoTypeInformation

Write-Host "All tables exported successfully."

# Export columns for all tables
foreach ($table in $allTables) {
$columns = Get-CdsTableColumn -Connection $connection -EntityLogicalName $table.LogicalName
$columns | Select-Object @{N="Table";E={$table.DisplayName}}, LogicalName, DisplayName, AttributeType, IsRequired | Export-Csv -Path "C:\Dataverse_Schema\AllColumns.csv" -Append -NoTypeInformation
}

Write-Host "All columns exported successfully."

Step 8: Verify the Exported Files

Go to C:\Dataverse_Schema\ and verify that the following files are generated:
TableSchema.csv (Contains table-level details)
ColumnSchema.csv (Contains column details of a specific table)
Schema.json (Contains schema in JSON format)
AllTables.csv (Contains details of all tables)
AllColumns.csv (Contains all columns from all tables)


Step 9: Disconnect from Dataverse

Once the export process is completed, disconnect from Dataverse.

Disconnect-CdsService -Connection $connection
Write-Host "Disconnected from Dataverse."
Posted Under PNP PowerShellAutomation CDS Column Metadata Common Data Service Data Management Dataverse Microsoft 365 Power platform Powershell Schema Export Table Metadata

Post navigation

Managing Columns in a Dataverse Table using PowerShell
Importing Data into Dataverse using PowerShell

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025
  • Recursive Queries in T-SQL
  • Generating Test Data with CROSS JOIN
  • Working with Hierarchical Data
  • Using TRY_CAST vs CAST

Recent Comments

  1. Michael Francis on Search , Filter and Lookup in power apps
  2. A WordPress Commenter on Hello world!

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • January 2022

Categories

  • Active Directory
  • AI
  • AngularJS
  • Blockchain
  • Button
  • Buttons
  • Choice Column
  • Cloud
  • Cloud Computing
  • Data Science
  • Distribution List
  • DotNet
  • Dynamics365
  • Excel Desktop
  • Extended Reality (XR) – AR, VR, MR
  • Gallery
  • Icons
  • IoT
  • Java
  • Java Script
  • jQuery
  • Microsoft Teams
  • ML
  • MS Excel
  • MS Office 365
  • MS Word
  • Office 365
  • Outlook
  • PDF File
  • PNP PowerShell
  • Power BI
  • Power Pages
  • Power Platform
  • Power Virtual Agent
  • PowerApps
  • PowerAutomate
  • PowerPoint Desktop
  • PVA
  • Python
  • Quantum Computing
  • Radio button
  • ReactJS
  • Security Groups
  • SharePoint Document library
  • SharePoint online
  • SharePoint onpremise
  • SQL
  • SQL Server
  • Template
  • Uncategorized
  • Variable
  • Visio
  • Visual Studio code
  • Windows
© Rishan Solutions 2025 | Designed by PixaHive.com.
  • Rishan Solutions