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

Not that it cannot be done with one command, but I think it will look more readable in two. I'll let you do it in one as an exercise 😉

$operation = @{
    Uri = "BulkDelete"
    Method = "POST"
    Value = @{
        QuerySet = @(@{
            EntityName="account"
            ColumnSet = @{ AllColumns = $true }
        })
        JobName = "Bulk delete all rows from account table"
        SendEmailNotification = $false
        ToRecipients = @(@{
            activitypartyid = "00000000-0000-0000-0000-000000000000"
            "@odata.type" = "Microsoft.Dynamics.CRM.activityparty"
        })
        CCRecipients = @(@{
            activitypartyid = "00000000-0000-0000-0000-000000000000"
            "@odata.type" = "Microsoft.Dynamics.CRM.activityparty"
        })
        RecurrencePattern = ""
        StartDateTime = Get-Date
        RunNow = $false
    }
} | ConvertTo-Json -Depth 4
Send-DataverseOperation -InputJson $operation

Now, let's break it down. The first line of the script is actually building a Hashtable and converts it to JSON. You can write it as JSON in the first place if you prefer. I did it with a Hashtable, because in real-world PowerShell scripts you are usually dealing with Hashtables.

Note that you should be already connected to Dataverse using 'Connect-Dataverse' before running the above commands. Send-DataverseOperation is part of PSDataverse module. To know more, I suggest you read about it here.

Last updated

Was this helpful?