title: PowerShell find and replace in different directories
body: <p>I am trying to make my PS script look in the directory as follows...</p>
  
  <pre><code>C:\FAKEENV
   └───DEVbox
      ├───PRD
      |    └──BatFile.txt
      └───STG
           └──BatFile.txt
  </code></pre>
  
  <p>What I am trying to do is see if either .txt has changed in the past 12 hours. If they have, replace a string in the bat file from 'dev' to 'stg' in the STG folder and 'stg' to '' (nothing) in the PRD folder.  I have changed variable and manipulated my code for hours with no luck.  I know my logic is just wrong because when I step through it never gets to the if statement that will manipulate the bat files.</p>
  
  <pre><code>Clear-Host
  $date = Get-Date
  $hours = '-12'    
  
  #$StgDestFile = 'C:\FakeEnv\DEVbox\STG'
  #$PrdDestFile = 'C:\FakeEnv\DEVbox\PRD'
  $dest_file = 'C:\FakeEnv\DEVbox'
  
  foreach($file in (Get-ChildItem $dest_file -Recurse))
  {
    #Check for changes from last $hours
    if($file.LastWriteTime -gt ($date).AddHours($hours))            
    {
        if($file -eq 'STG')
        {
          (Get-Content $dest_file\STG\BatFile.txt) | Foreach-Object {
            $_ -replace 'dev', 'stg' `
            #Format: -replace 'SOMETHING', 'SOMETHING ELSE' `                   
          } | Set-Content $dest_file    
          #Insert logic for uninstall and install of 'feature'
          #Insert logic for confirmation message of changes
        }
        elseif($file -eq 'PRD')    
        {
          (Get-Content $dest_file\PRD\BatFile.txt) | Foreach-Object {
            $_ -replace 'dev', 'stg' `
            #Format: -replace 'SOMETHING', 'SOMETHING ELSE' `                   
          } | Set-Content $dest_file    
          #Insert logic for uninstall and install of 'feature'
          #Insert logic for confirmation message of changes    
        }
      }
    }
    #If no changes occurded, log that nothing happened       
    else
    {
      $LogDestination = 'C:\FakeEnv\Logs'
      $LogPathExist = Test-Path "$LogDestination"
      #Do this if folder does not exist
      #If the folder has not already been created, create it and write to log file
      if($LogPathExist -eq $false)
      {
        New-Item $LogDestination -ItemType directory
        New-Item $LogDestination\log.log -ItemType file
        Add-Content $LogDestination\log.log "Script detected no changes in $dest_file on $date"
      }
      #Do this is folder does exist
      #if the folder exists, append to log file
      else
      {
        Add-Content $LogDestination\log.log "`nScript detected no changes in $dest_file on $date"
      }
    }    
  </code></pre>