AzDataFactoryV2IntegrationRuntimeDependencies.psm1

<#
     .SYNOPSIS
         This Command provide the list of Linked Services and Azure Data factories that depend on the Integration runtime within an Azure Data Factory.
   
    
   
     .DESCRIPTION
         This function provides the list of Linked Services and Azure Data factories that depend on the Integration runtime within an Azure Data Factory.
   
    
   
     .PARAMETER ResourceGroupName
     The resource group containing the DataFactory V2
   
    
   
     .PARAMETER DataFactoryName
     The name of the DataFactory V2.
   
    
   
     .PARAMETER IntegrationRuntimeName
     The name of the IntegrationRuntimeName in the DataFactory V2.
   
    
   
     .EXAMPLE
     Get-AzDataFactoryV2IntegrationRuntimeDependencies -ResourceGroupName "<<RGName>>" -DataFactoryName "<<ADFV2Name>>"
     Get-AzDataFactoryV2IntegrationRuntimeDependencies -ResourceGroupName "<<RGName>>" -DataFactoryName "<<ADFV2Name>>" -IntegrationRuntimeName "<<IntegrationRuntimeName>>"
     
#>

Function Get-AzDataFactoryV2IntegrationRuntimeDependencies
{

 

    Param 
    (
    [Parameter(Mandatory=$true)]
    [string] $ResourceGroupName ,
    [Parameter(Mandatory=$true)]
    [string] $DataFactoryName ,
    [Parameter(Mandatory=$false)]
    [string] $IntegrationRuntimeName 

    )



$htDependee = @{}

if(!$IntegrationruntimeName)
{
$AllIntegrationruntime=Get-AzDataFactoryV2Integrationruntime -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName 

}
else
{
$AllIntegrationruntime=Get-AzDataFactoryV2Integrationruntime -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $IntegrationruntimeName
}



$AllLinkedService=Get-AzDataFactoryV2LinkedService -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName 

for ($i=0;$i -lt $AllIntegrationruntime.Count ; $i++)
{
$IRDependantObjects=@()
for ($j=0;$j -lt $AllLinkedService.Count ; $j++)
{

if($AllLinkedService[$j].Properties.ConnectVia.ReferenceName -eq $AllIntegrationruntime[$i].Name)
  {
  
  $IRDependantObjects=$IRDependantObjects+$AllLinkedService[$j].Name
  }

 
}



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

       FOREACH($IRDep in $IRDependantObjects){
    if ($htDependee[$AllIntegrationruntime[$i].Name] -notcontains $IRDep) 
     

        {

        $htDependee[$AllIntegrationruntime[$i].Name] += $IRDep
        }
     }
 }
else{
     FOREACH($IRDep in $IRDependantObjects){
    if ($htDependee[$AllIntegrationruntime[$i].Name] -notcontains $IRDep) 
     

        {

        $htDependee[$AllIntegrationruntime[$i].Name] += ,$IRDep
        }
     }

}
}
}

#For Identifying IR Shared dependencies
for ($i=0;$i -lt $AllIntegrationruntime.Count ; $i++)
{

$IRLink=Get-AzDataFactoryV2Integrationruntime -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -Name $AllIntegrationruntime[$i].Name -Status


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

foreach($Share in $IRLink.Links.DataFactoryName)
{
 
$ADFShare= "External_ADF_Share:" + $Share

    if ($htDependee[$AllIntegrationruntime[$i].Name] -notcontains $ADFShare) 
     

        {

        $htDependee[$AllIntegrationruntime[$i].Name] += $ADFShare
        }

}

}#endif

else{
     FOREACH($Share in $IRLink.Links.DataFactoryName){
     $ADFShare= "ADF_Share:" + $Share
    if ($htDependee[$AllIntegrationruntime[$i].Name] -notcontains $ADFShare) 
     

        {

        $htDependee[$AllIntegrationruntime[$i].Name] += ,$ADFShare
        }
     }

}

}

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

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

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

}
 
}



Export-ModuleMember -Function Get-AzDataFactoryV2IntegrationRuntimeDependencies