# Set the subscription ID, resource group name, and data factory name $subscription_id = "{subscription-id}" $resource_group = "{resource-group-name}" $data_factory = "{data-factory-name}" $response = Invoke-AzRestMethod -Method GET -Path "/subscriptions/$subscription_id/resourcegroups/$resource_group/providers/Microsoft.DataFactory/factories/$data_factory/adfcdcs?api-version=2018-06-01" Write-Output "Fetching CDCs. Status = $($response.StatusCode)" # Check if the response is successful if ($response.StatusCode -eq 200) { # Parse the response as JSON $data = $response.Content | ConvertFrom-Json Write-Output "#Total CDCs = $($data.value.Count)" # Filter the CDCs by status $filtered_CDCs = $data.value | Where-Object {$_.properties.status -eq "PipelineRunCreated"} # Display the filtered CDCs Write-Output "#Running CDCs = $($filtered_CDCs.Count)" # Initialize an empty string to store the comma separated running CDC names $running_cdc_names = "" # Loop through each CDC in the filtered_CDCs variable foreach ($cdc in $filtered_CDCs) { # Get the name of the CDC $cdc_name = $cdc.name Write-Output "Stopping CDC = $($cdc_name)" # Stop the CDCs $stop_response = Invoke-AzRestMethod -Method POST -Path "/subscriptions/$subscription_id/resourcegroups/$resource_group/providers/Microsoft.DataFactory/factories/$data_factory/adfcdcs/$cdc_name/Stop?api-version=2018-06-01" Write-Output "Stopping CDC = $cdc_name status = $($stop_response.StatusCode)" if ($stop_response.StatusCode -eq 200) { # Append the CDC name to the string with a comma separator $running_cdc_names += "$cdc_name," } } # Remove the trailing comma from the string $running_cdc_names = $running_cdc_names.TrimEnd(",") Write-Output "Stopped CDCs = $running_cdc_names" # Set an output variable with the comma separated CDC names, to be used and accessed by post script later on } else { # Display the error message Write-Error "Error: $($response.StatusCode)" }