private/Update-GlobalParameters.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function Update-GlobalParameters {
    [CmdletBinding()]
param
(
    [Parameter(Mandatory)] [Adf] $adf,
    [Parameter(Mandatory)] $targetAdf
)

    Write-Debug "BEGIN: Update-GlobalParameters"

    if ($adf.GlobalFactory.body.Length -gt 0)
    {
        $newGlobalParameters = New-Object 'system.collections.generic.dictionary[string,Microsoft.Azure.Management.DataFactory.Models.GlobalParameterSpecification]'
        Write-Verbose "Parsing JSON..."
        $globalFactoryObject = [Newtonsoft.Json.Linq.JObject]::Parse($adf.GlobalFactory.body)
        #$globalParametersObject = $globalFactoryObject.properties.globalParameters

        $gpExist = Get-Member -InputObject $adf.GlobalFactory.GlobalParameters -name "properties" -Membertype "Properties"
        if ($null -ne $gpExist)
        {

            Write-Host "Adding global parameter..."
            foreach ($p in $adf.GlobalFactory.GlobalParameters.properties.globalParameters.PSObject.Properties)
            {
                # $p.Name
                # $p.Value.type
                # $p.Value.value
                $gpspec = New-Object 'Microsoft.Azure.Management.DataFactory.Models.GlobalParameterSpecification'
                $gpspec.Type = $p.Value.type
                $gpspec.Value = $p.Value.value
                $globalParameterValue = $gpspec
                $newGlobalParameters.Add($p.Name, $globalParameterValue)
            }
            $targetAdf.GlobalParameters = $newGlobalParameters

            # Write-Host "--- newGlobalParameters ---"
            #$newGlobalParameters.Values | Out-Host

            Write-Verbose "Updating $($newGlobalParameters.Count) global parameters..."
            Set-AzDataFactoryV2 -InputObject $targetAdf -Force | Out-Null
            Write-Host "Update of $($newGlobalParameters.Count) global parameters complete."
        }
    }
    
    Write-Debug "END: Update-GlobalParameters"

}