我需要为此脚本执行的每个操作创建一个日志文件。
我尝试使用redirection(>>),但是无法获取输出以实际写入文件。
while($true){
$FromMC = Get-ChildItem -Path "\\x\From MC" -Filter *.mpg
Write-Host "Checking '\\x\From MC' for files" -ForegroundColor Cyan
Write-Host $FromMC.count"Files Found" -ForegroundColor Cyan
Write-Host ""
ForEach($file in $FromMC){
try{
Move-Item -Filter 7ST* -Path $file.Fullname -Destination "\\x\programs\7TH STREET THEATER" -Verbose -Force -ErrorAction Stop
}
catch{...}
Write-Host "Pausing for"$ts.Minutes"minutes..." -ForegroundColor Cyan
Write-Host "Ctrl+C to Stop"
Write-Host ""
Start-Sleep -Seconds $ts.TotalSeconds
}
我希望输出与进入外壳的“ -verbose”输出完全相同。输出类型:写主机,详细,写警告
我觉得解决方案非常简单,我只是忽略了它。
记录通常会写入控制台的所有内容,例如-verbose
可以使用的时间Start-Transcript
和完成时间Stop-Transcript
。
例:
Start-Transcript -Path "C:\logs.txt"
#run code you want to capture
Stop-Transcript
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句