title: Powershell script write to one file simultaneously Out-File -FilePath -InputObject -Append
body: <p>I made a powershell script that writes data to one text file.</p>
  
  <p>Script is being executed with 3rd party software deploying program. Good thing is that it waits when computer is online and it executes a job, bad thing is when script is being executed on already 100+ online computers I got information from only 8 computers and 2 empty lines.</p>
  
  <p>Most likely it happened because powershell script was running simultaneously on 100+ computers and that file was in use.</p>
  
  <p>No way to use "wait for script being executed on first computer" in 3rd party software deployment program.</p>
  
  <p>The problem is with line -</p>
  
  <pre><code>$srvpath = [path to text file]
  $computer = "Name of computer"
  $data = "Some data not more than ~30 characters"
  Out-File -FilePath $srvpath -InputObject "$computer - $data" -Append
  </code></pre>
  
  <p>My current solution is to make temporary file for each computer separately and later launch 2nd script that will read those files write to one file (sort alphabetically) and delete temporary files.</p>
  
  <p>But I would like to stick with one script so is it possible to check if data was written to the file or check if text file is already in use and then wait? Would be nice to avoid extra empty lines as well, but that's not a big issue.</p>