Powershell - Loop through environments #202
-
Hello, Just started looking at automating some admin tasks using the Admin API and PowerShell. We have a number of BC environments in our Tenant and I would like to be able to loop through them and run an activity on each one. I'm not great at PowerShell and have tried a few things but not having any success. The idea is to get the list of environments using the API and then process through each one. I can do this by manually creating an array in PowerShell but this will need updating if we add additional environments. Would someone be able to advise me on this,? Thanks Nick |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
The API to get the environments is documented here: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/administration-center-api_environments#get-environments-and-get-environments-by-application-family You need to call /admin/v2.18/applications/environments. Then you will get all the environments back, and you can then iterate over them. |
Beta Was this translation helpful? Give feedback.
-
You can probably do something like this: |
Beta Was this translation helpful? Give feedback.
You can probably do something like this:
$result = ConvertFrom-Json $httpResult.Content
foreach ($environment in $result.value)
{
write-host $environmetn.name
}