AzSynapseDataflowDependencies.psm1

<#
     .SYNOPSIS
         This Command provide the list of Pipelines that depend on the Dataflow within Synapse.
 
 
 
     .DESCRIPTION
         This function provides the list of Pipelines that depend on the Dataflow within Synapse.
 
 
 
     .PARAMETER WorkspaceName
     The WorkspaceName of Synapse
 
 
 
     .PARAMETER DataflowName
     The name of the Dataflow in Synapse.
 
 
 
     .EXAMPLE
     Get-AzSynapseLinkedServiceDependencies -WorkspaceName "<<WorkspaceName>>"
     Get-AzSynapseLinkedServiceDependencies -WorkspaceName "<<WorkspaceName>>" -DataflowName "<<DataflowName>>"
 
#>

Function Get-AzSynapseDataflowDependencies
{

 

 

    Param 
    (
    [Parameter(Mandatory=$true)]
    [string] $WorkspaceName ,
    [Parameter(Mandatory=$false)]
    [string] $DataflowName 
    )

 


$htDependee=@{}
IF(!$DataflowName)
{
$AllDataflow=Get-AzSynapseDataflow -WorkspaceName $WorkspaceName
}
ELSE
{
$AllDataflow=Get-AzSynapseDataflow -WorkspaceName $WorkspaceName -Name $DataflowName
}

$AllPipeline=Get-AzSynapsepipeline -WorkspaceName $WorkspaceName

for ($i=0;$i -lt $AllDataflow.Count ; $i++)
{
$DFDependantObjects=@()
for ($j=0;$j -lt $AllPipeline.Count ; $j++)
{
$DFMatch=@()



$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Dataflow.ReferenceName #outer activities
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Dataflow.ReferenceName #outer Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Dataflow.ReferenceName #outer Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.IfTrueActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.IfTrueActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.IfTrueActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.IfFalseActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.IfFalseActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.IfFalseActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.DefaultActivities.Dataflow.ReferenceName #Switch Default outer
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.DefaultActivities.Dataflow.ReferenceName  #Switch Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.DefaultActivities.Dataflow.ReferenceName #Switch Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Cases.Activities.Dataflow.ReferenceName  #Switch case outer
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Cases.Activities.Dataflow.ReferenceName   #Switch Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Cases.Activities.Dataflow.ReferenceName   #Switch Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.Dataflow.ReferenceName #Foreach / until
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.Dataflow.ReferenceName #Foreach / until copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.Dataflow.ReferenceName #Foreach / until copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.IfTrueActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.IfTrueActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.IfTrueActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.IfFalseActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.IfFalseActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.IfFalseActivities.Dataflow.ReferenceName #Outer IF
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.DefaultActivities.Dataflow.ReferenceName #Switch Default outer
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.DefaultActivities.Dataflow.ReferenceName  #Switch Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.DefaultActivities.Dataflow.ReferenceName #Switch Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.Cases.Activities.Dataflow.ReferenceName  #Switch case outer
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.Cases.Activities.Dataflow.ReferenceName   #Switch Copy
$DFMatch=$DFMatch+$AllPipeline[$j].Activities.Activities.Cases.Activities.Dataflow.ReferenceName   #Switch Copy

$DFMatch=$DFMatch |Select -Unique

foreach ($ite in $DFMatch)
{ if($ite -eq $AllDataflow[$i].Name)
  {

  $DFDependantObjects=$DFDependantObjects+$AllPipeline[$j].Name
  }
}

}






if($DFDependantObjects.count -ne 0)
    {
    
  if ($htDependee.ContainsKey($AllDataflow[$i].Name))
  {

       FOREACH($DFDep in $DFDependantObjects){
    if ($htDependee[$AllDataflow[$i].Name] -notcontains $DFDep) 
     

        {

        $htDependee[$AllDataflow[$i].Name] += $DFDep
        }
     }
 }
else{
     FOREACH($DFDep in $DFDependantObjects){
    if ($htDependee[$AllDataflow[$i].Name] -notcontains $DFDep) 
     

        {

        $htDependee[$AllDataflow[$i].Name] += ,$DFDep
        }
     }

}
}
}

for ($i=0;$i -lt $AllDataflow.Count ; $i++)
{

if($htDependee.ContainsKey($AllDataflow[$i].Name))
{

write-host  $AllDataflow[$i].Name 'has' $($htDependee[$AllDataflow[$i].Name]).Count 'Dependencies'
Write-Host  $AllDataflow[$i].Name "is used in" $($htDependee[$AllDataflow[$i].Name]) `n 
}
else
{
write-host $AllDataflow[$i].Name "has no / 0 Dependency" `n 
}

}
}



Export-ModuleMember -Function Get-AzSynapseDataflowDependencies