rwskas
asked on
Get-Content File Locked test?
I have a powershell script which every 30 seconds tries to read teh content of an output file. The output file is the result of running a script like this:
C:\scripts\myscript.ps1 > C:\temp\outputfile.txt
The problem I am running into is that occasionally (randomly) the Get-Content command files due to the file being locked.
How can I test that the file is not locked prior to my Get-Content command?
A function would be easiest, so that I could:
If (Test $filename) { get-content ... }
Thoughts?
C:\scripts\myscript.ps1 > C:\temp\outputfile.txt
The problem I am running into is that occasionally (randomly) the Get-Content command files due to the file being locked.
How can I test that the file is not locked prior to my Get-Content command?
A function would be easiest, so that I could:
If (Test $filename) { get-content ... }
Thoughts?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In the failure part you can check end emit the error by reading the $error[0] variable.
ASKER
Your solution works, its just not what I was asking..
ASKER