我已经创build了以下脚本:
#This scripts finds if 2 LST files were created today. #What date are we in $today = Get-Date #Are there two lst files? $Lst = @(Get-ChildItem 'PATH' -recurse -include @("*.lst") | Where-Object { $_.CreationTime -gt (Get-Date).Date }) if ($Lst.length -eq 2) { $LstStatus = "Files OK" $filename = (Get-ChildItem 'PATH' -recurse -include @("*.lst") | Where-Object { $_.CreationTime -gt (Get-Date).Date } | Select-Object Name) } else { $LstStatus = "LST ERROR" } #What do I want in the file $output = @(Write-Host -NoNewline @($today.ToShortDateString()) @($filename.name) $LstStatus) $output | Out-File PATH\lst_check.txt`
$output
有我需要的信息和lst_check.txt
被创build,但它是空的。
我错过了什么? 有没有其他的命令我应该更换Write-Host
?
Write-Host
直接写你的输出到主机应用程序,在你的情况下可能是控制台。
要输出到文件,请将值存储为字符串:
$output = "$($today.ToShortDateString()) $($filename.name) $LstStatus" Write-Host "This is the output: $output" $output | Out-File PATH\lst_check.txt