0

This seems like a very basic thing to do, but I am new to PowerShell and can't figure this out or find an example online.

I am reading a json file and checking whether any key, value pair has double underscore(__) substring as value. I need to replace that substring with some actual value.

Suppose below is my json file.

"parameters": {
     "tenantId": {
         "value": "adf/__TENANT_ID_AG08__"
      }

 }

And I am trying with the below code to find any substring which starts and ends with double underscore(__TENANT_ID_AG08__ in above example). It is unable to get any matches:

Get-ChildItem -Path $dirPath -Recurse -Filter *.json | 
Foreach-Object {
    $content = Get-Content $_.FullName 

    #Get all the matches with __*ag*__ in a file and replace it with the actual values.
    # UNABLE to get any match. 
    $placeholders = $content | Where-Object {$_ -match '__*AG*__'} 
    
    
    foreach($placeholer in $placeholers) {
       
       #Logic to replace the substring. 
       #...
       #...
       #..
        
    }
}

Assuming, in the above example I have __TENANT_ID_AG08__ value available which I read from the config file and I need to replace that substring.

How can I fix this?

Vikas Gupta
  • 10,779
  • 4
  • 35
  • 42

0 Answers0