Implementing logging (to log file) in Powershell Scripts
Many of the times one requires to setup logging for a script that is very huge in code and/or critical in it’s activities. Here is a quick PS function code that I authored which simply logs all the log statements to a given file (for this example, I used C:tempTest.log file). Code: $LogFile = ‘C:tempTest.log’ function MyLog { param ([string]$msg, [int]$flag) $date = get-date -format MM:dd:yyyy-HH:mm:ss Write-Output "msg received is [ $msg ] flag received is: [ $flag ]" | Out-File $LogFile -append if ($flag -eq 0) { Write-Output "$date INFO: $msg" | Out-File $LogFile […]
Read more