A nice, short function this one;
<# .SYNOPSIS Tests if a file is locked. #>
function Test-FileLocked
{
param
(
[string]$FilePath
)
try { [IO.File]::OpenWrite($FilePath).close();return $false }
catch {return $true}
}