Create Log File in Powershell

前端 未结 8 2128
半阙折子戏
半阙折子戏 2020-11-30 22:11

I have the below code and currently it loads all the information on screen. I want it to log to a log file on D:\\Apps\\Logs.

The log file needs to have the name of

8条回答
  •  借酒劲吻你
    2020-11-30 22:47

    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
    }
    

    Then replace your Write-host calls with LogWrite.

提交回复
热议问题