Powershell write to one file simultaneously Out-File -FilePath -InputObject
I made a powershell script that writes data to one text file.
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.
Most likely it happened because powershell script was running
simultaneously on 100+ computers and that file was in use.
No way to use "wait for script being executed on first computer" in 3rd
party software deployment program.
The problem is with line -
$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
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.
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.
No comments:
Post a Comment