Home > other >  How to execute COSMOS DB stored procedure with parameters via powershell
How to execute COSMOS DB stored procedure with parameters via powershell

Time:09-10

Looking for a powershell script/rest API to execute cosmos db stored procedure with partition key value.

CodePudding user response:

You can use the REST API to execute Stored Procedures.

https://{databaseaccount}.documents.azure.com/dbs/{db-id}/colls/{coll-id}/sprocs/{sproc-name}

CodePudding user response:

There is no native means to interact with Cosmos DB on its data-plane via PowerShell. There are three options you can explore. One of them is calling REST directly from PowerShell as indicated in the previous answer below. Your other options...

  • You can use this PowerShell Rest API Sample from the .NET SDK GitHub Repo. However, this requires authenticating via the REST API mentioned in the previous answer which can be a bit cumbersome.

  • You can create your own Custom PowerShell cmdlet in C#/.NET and then call that from your PS script. This may take longer than the example above but is easier to write and maintain. It also gives you the ability to do whatever you were looking to do in a stored procedure and simply implement in C# using the .NET SDK which can also yield benefits in maintainability.

  • Related