我正在编写powershell脚本来从C盘读取文件名并写入文本文件。我正在尝试记录数据记录之前和之后的开始时间和结束时间。我看到了
的问题该进程无法访问该文件' C:\ Logs.txt'因为它正被另一个进程使用。
是否有任何选项可以写入打开的文本文件。
function log($string)
{
$logfile = "C:/Logs.txt"
write-host $string
$string | out-file -Filepath $logfile -append
}
workflow testflow{
Param ($folderPath)
$Files = Get-ChildItem $folderPath
log 'starting'
ForEach -Parallel($file in $Files)
{
try{
log $file.FullName
}
Catch{
log 'error occured'
}
}
log 'end'
}