How to delete Global Parameters using Powershell Command

sachin gupta 376 Reputation points
2022-06-02T02:52:16.367+00:00

Hello Everyone,

I have created a number of Global Parameters in DEV Azure Data Factory which is being used in many pipelines. I have deployed those Global parameters using ARM template to our QA environment.
Now I have deleted few parameters from Dev environment and when I re deployed the ARM template, those parameters are not getting deleted from QA environment.
I did not find any other way to delete from QA environment as we do not have delete permissions in QA.
Can you please suggest what can be the next steps? I am looking some power shell command way to delete those parameters.

Any help is much appreciated.

Thanks

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} votes

Accepted answer
  1. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2022-06-06T08:25:30.253+00:00

    Hi @sachin gupta ,

    Thankyou for using Microsoft Q&A platform and thankyou for posting your query here.

    It seems you expected those global parameters which were deleted from DEV env to be deleted from UAT environment as well after deployment . However, it was not the actual case, so you are trying to find out a way to delete global parameters from UAT directly using powershell script. Please correct me if my understanding has any gap.

    First of all, if you check the GIT repo, global parameters has separate .json file by default they are not included in the ARM template.
    208663-image.png

    In order to include the global paramaters in the ARM template, you need to check the 'Include Global parameter in ARM template' option in manage tab.

    208617-image.png

    Post doing that, you will be able to see the global parameter got added in ARM template .json file , which can be included as a part of CICD deployment as well.

    208618-image.png

    Now, coming to your scenario, where you need to delete Global parameter from UAT env, you can use the following script to achieve that.

    Note: This script will delete all the Global parameters from UAT , not the selected ones. Post deleting all GPs , you can redeploy .

    param  
    (  
        [parameter(Mandatory = $true)] [String] $globalParametersFilePath,  
        [parameter(Mandatory = $true)] [String] $resourceGroupName,  
        [parameter(Mandatory = $true)] [String] $dataFactoryName  
    )  
      
    Import-Module Az.DataFactory  
    $newGlobalParameters = New-Object 'system.collections.generic.dictionary[string,Microsoft.Azure.Management.DataFactory.Models.GlobalParameterSpecification]'  
      
    Write-Host "Getting global parameters JSON from: " $globalParametersFilePath  
    $globalParametersJson = Get-Content $globalParametersFilePath  
      
    Write-Host "Parsing JSON..."  
    $globalParametersObject = [Newtonsoft.Json.Linq.JObject]::Parse($globalParametersJson)  
      
    # $gp in $factoryFileObject.properties.globalParameters.GetEnumerator())   
    # may  be used in case you use non-standard location for global parameters. It is not recommended.   
    foreach ($gp in $globalParametersObject.GetEnumerator()) {  
        Write-Host "Removing global parameter:" $gp.Key  
        $globalParameterValue = $gp.Value.ToObject([Microsoft.Azure.Management.DataFactory.Models.GlobalParameterSpecification])  
        $newGlobalParameters.Remove($gp.Key)  
    }  
      
    $dataFactory = Get-AzDataFactoryV2 -ResourceGroupName $resourceGroupName -Name $dataFactoryName  
    $dataFactory.GlobalParameters = $newGlobalParameters  
      
    Write-Host "Updating" $newGlobalParameters.Count "global parameters."  
      
    Set-AzDataFactoryV2 -InputObject $dataFactory -Force  
    

    Download the Global parameter .json file from dev GIT repo in your local , and provide the same file path when asked . Also , provide UAT resource group name and adf name while running the script .

    For more info, please check this MS doc which talks about how to add global parameter while deploying : Deploying using PowerShell

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.