Power Platform Tidbits 9: Truncate a table in Dataverse with one command

The latest version of PSDataverse (v0.0.3) brings several quality and performance improvements. But, it also has a new command that lets you delete all the rows in a table in Dataverse as fast as it can be done. Here is the easiest way to use it:

Clear-DataverseTable lead

If you need to truncate multiple tables in one go, you can just pass multiple table names separated by comma.

Clear-DataverseTable lead, opportunity

You can also pipe the list of table names to Clear-DataverseTable. This can be useful for when you are receiving the list from some other command.

@(lead, opportunity) | Clear-DataverseTable

Note that you should be already connected to Dataverse using ‘Connect-Dataverse’ before running the ‘Clear-DataverseTable`. This command is part of PSDataverse module that you can get from PowerShell Gallery. To know more, I suggest you read about it in here.

Good to know

When passing in a list of values separated by comma, PowerShell assumes that you are sending an array. The full syntax for literally defining an array is @(item1, item2,…). Knowing that, if you pass an array however way to the Clear-DataverseTable it would work. To know more about arrays in PowerShell and all the different ways to define them, check About Arrays in the official documentation.

Power Platform Tidbits 8: Download the full metadata of your Dataverse environment by one PowerShell command

You can always visit get the full metadata of a Power Platform environment (or Dynamics 365) from https://{your-environment}.{region-specific-url}/api/data/v9.2/$metadata. For example if your environment is hosted in Europe, the URL can be:


But sometimes the data can be too much for your browser to digest, specially if you have a plugin that formats or beautifies XML content. In that case you can always use PowerShell or more precisely PSDataverse to download and save the metadata as an XML file. It just takes two lines in Powershell, and the first line is to connect.

Connect-Dataverse "authority=https://login.microsoftonline.com/{tenant-id}/oauth2/authorize;clientid=1950a258-227b-4e31-a9cf-717495945fc2;resource=https://mytestenvironment.crm4.dynamics.com/;device=true"
Send-DataverseOperation "`$metadata" | Select-Object -ExpandProperty Content | Set-Content ".\schema.xml"

A screenshot of Windows Terminal. The screenshot shows two commands and their result. The first command is "Connect-Dataverse" with a connection string that uses device flow to authenticate. The second command is "Send-DataverseOperation "`$metadata" | Select-Object -ExpandProperty Content | Set-Content -Path ".\schema.xml".
Both commands are executed successfully.
In my case, it took 8 seconds to download and save the file from a trial environment.

If you are not familiar with PSDataverse, just know that it takes only one line to install it. Read more in the official Github repository