title: PowerShell to search for string in all users folder and to add string if not exist
body: <p>I am trying to write a script that will</p>
  
  <ol>
  <li>Search for specific string in the file that is located in each user profile on C:\users\USERNAME\AppData\Roaming\Nextcloud\nextcloud.cfg</li>
  <li>If the string
  
  <pre>
  "[BWLimit]","downloadLimit=250","uploadLimit=250","useDownloadLimit=1","useUploadLimit=1"
  </pre>
  
  exists the file should not be touched </li>
  <li>If the string does not exists it should add it</li>
  </ol>
  
  <p>What I did till now is that I made a script, using examples from this great site, that works BUT it only works when I trigger it locally. I need the script to work remotely (I use PDQ to push the script)</p>
  
  <p>The script is as follows</p>
  
  <pre><code>$content = Get-Content "C:\users\$($env:USERNAME)\AppData\Roaming\Nextcloud\nextcloud.cfg"
  $sites   = "[BWLimit]","downloadLimit=250","uploadLimit=250","useDownloadLimit=1","useUploadLimit=1"
  
  if (!(Test-Path "C:\users\$($env:USERNAME)\AppData\Roaming\Nextcloud\nextcloud.cfg")) {
      New-Item -Path "C:\users\$($env:USERNAME)\AppData\Roaming\Nextcloud" -Name nextcloud.cfg -Type "file"
  } else {
      foreach ($site in $sites) {
          if (-not ($content -contains $site)) {
              $site | Out-File "C:\users\$($env:USERNAME)\AppData\Roaming\Nextcloud\nextcloud.cfg" -Append -Encoding utf8
          }
      }
  }
  </code></pre>