DEV Community

Riccardo Gregori
Riccardo Gregori

Posted on

Invoke Dataverse AI Actions via Powershell

A few days ago, I was πŸ› οΈ thinking to create a command for PACX that allowed me to call via command line the new Dataverse AI functions πŸ› οΈ.

But I'm lazy, so I try to avoid reinventing the wheel when there is one there already available that just fits my needs.

Here is how you can invoke the πŸ€– Dataverse AI πŸ€– actions via Powershell leveraging Microsoft.Xrm.Data.PowerShell:

# setup a connection towards your dataverse environment
$conn = Get-CrmConnection -ConnectionString $connStr

# invoke the action
$response = Invoke-CrmAction -conn $conn -Name AIReply -Parameters @{ Text = "Compute the square root of PI" }

# print out the response
$response
Enter fullscreen mode Exit fullscreen mode

The square root of PI


Recently I've also known about this powershell library by Rob Wood and... this is how to do the same via Rnwood.Dataverse.Data.PowerShell.


# install the powershell module
Install-Module Rnwood.Dataverse.Data.PowerShell -Scope CurrentUser

# setup a connection towards your dataverse environment
$c = Get-DataverseConnection -url https://myorg.crm4.dynamics.com -interactive

# create the request
$request = new-object Microsoft.Xrm.Sdk.OrganizationRequest "AIReply"
$request["Text"] = "Can you compute the square root of PI?"
$response = Invoke-DataverseRequest -connection $c -request $request

# print out the response
$response

Enter fullscreen mode Exit fullscreen mode

Et voilΓ :

The square root of PI

Of course it works with any organization request 😎

References:

Top comments (0)