我想要得到我的Powershell脚本所做的事情的日志文件



我一直试图得到的步骤,脚本做一个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
}

提示吗?

您可以使用以下代码将文本写入txt:

"Test" | Out-File -FilePath "Your Path to the txtfile" -Append

我将创建一个函数,所以你不必多次写这行

编辑:您还可以添加时间戳:

"Test " + $(Get-Date -Format g) | out-file....

最新更新