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.
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.
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.
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
or upvote
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