【发布时间】:2018-01-04 20:55:01
【问题描述】:
我正在尝试编写一个 powershell 脚本来将命令的输出写入文件。它第一次运行得很好。当我重新运行脚本时,它会出现错误
Out-File : The process cannot access the file '//Filepath' because it is
being used by another process.
+ (Invoke-Command -Session $s -ScriptBlock $command )| Out-File
$file -For ...
代码块:
$command = {
$x = (Get-Date).AddMinutes(-5).ToShortTimeString() ;
$y = "{0:HH:mm}" -f [datetime] $x ;
cd $path ;
dumplog ctisvr /bt $y /m "CSTAUniversalFailureConfEvent"
}
#$s = New-PSSession -ComputerName
(Invoke-Command -Session $s -ScriptBlock $command )| Out-File $file -Force
【问题讨论】:
-
听起来您有一个需要关闭的开放 IO 流。您可能需要检查进程监视器以查看该转储日志命令是否实际上仍然使您的文件处于打开状态。
-
我只有一件事写入文件,即“Out-File $file -Force”。 Dumplog 只有开始和结束时间,因此不会进入无限循环。 Out-File 是否有任何命令来结束该流?
标签: powershell file-io out