private/Remove-UnusedDatasetsFromAdf.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Remove-UnusedDatasetsFromAdf {
    [CmdletBinding()]
    param (
        [parameter(Mandatory = $true)] [Adf] $Adf,
        [Parameter(Mandatory = $false)] [switch] $SoftDelete
    )

    $dataset_list = $Adf.GetUnusedDatasets()
    
    foreach($dataset_name in $dataset_list){
        # get the dataset object
        $obj = Get-AdfObjectByName -adf $Adf -type "Dataset" -name $dataset_name

        # remove it from the ADF object
        $Adf.DataSets.Remove($obj)

        # if softdelete is not activated, then also delete the json file.
        if(!$SoftDelete){
            Remove-Item $obj.FileName
        }
    }

}