我一直在尝试将脚本执行的步骤转换为txt文件,但我无法理解它
$days = -2
$date = (get-date).adddays($days)
$lastboot = (Get-WmiObject Win32_OperatingSystem).LastBootUpTime
$Computer = Get-ADComputer -SearchBase 'OU=TEST-OU,OU=EDV,DC=Kolbe-Druck,DC=de' -Filter '*' | Select -EXP Name
$lastbootconverted = ([WMI]'').ConvertToDateTime($lastboot)
write-host $date
write-host $lastboot
write-host $lastbootconverted
if($date -gt $lastbootconverted)
{
write-host Need to reboot
(Stop-Computer $Computer -Force)
}
else
{
write-host no need to reboot
}
任何提示?
答案 0 :(得分:1)
您可以使用以下代码将文本写入文本:
"Test" | Out-File -FilePath "Your Path to the txtfile" -Append
我会创建一个函数,所以你不必多次写这行
编辑: 您还可以添加时间戳:
"Test " + $(Get-Date -Format g) | out-file....