Skip to content

Instantly share code, notes, and snippets.

@SQLvariant
Created August 5, 2022 13:48

Revisions

  1. SQLvariant created this gist Aug 5, 2022.
    11 changes: 11 additions & 0 deletions Find_and_Replace.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <# Search for something inside an ADF file and replace it. #>
    $Datasets = dir 'C:\temp\MDD-ADF-Test-Repo\dataset' -Recurse
    foreach($Dataset in $Datasets.Where({$_.Mode -ne 'd----'})){
    $Dataset.Name

    if((Get-Content $Dataset.FullName | foreach{ $_ -match 'AzureSqlDatabase1' }) -eq $true ){"Fix it"
    (Get-Content $Dataset.FullName).Replace('Azure_SqlDatabase1', 'MDD_SampleSQL_LS') | Set-Content -Path $Dataset.FullName }
    else{"Nothing to do"}
    }

    <# This isn't limited to just Datasets. you can go up one level and do the replace on every directory if you include the -Recurse parameter. #>