且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Powershell 中创建日志文件

更新时间:2023-12-06 13:03:34

把这个放在文件的顶部:

Put this at the top of your file:

$Logfile = "D:\Apps\Logs\$(gc env:computername).log"

Function LogWrite
{
   Param ([string]$logstring)

   Add-content $Logfile -value $logstring
}

然后将您的 Write-host 调用替换为 LogWrite.

Then replace your Write-host calls with LogWrite.