Create logs file


Will write only output was instructed with >>.

If need to all out put use start-transcript and stop-transcript

set-location "C:\Temp"
$dateinfo = get-date -Format "MMddyyy_HHmmss"
$logfilename = "log" + $dateinfo + ".log"

get-date >> $logfilename
write-output "Script starting...." >> $logfilename
Get-Process | select -First 5 >> $logfilename
get-date >> $logfilename
Write-Output "Script end!" >> $logfilename

Output in .log file

Sunday, May 7, 2023 7:27:11 PM


Script starting....

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName                                                                                                                                                                                            
-------  ------    -----      -----     ------     --  -- -----------                                                                                                                                                                                            
   1585      44    58264      29464     132.52   9492   2 1Password                                                                                                                                                                                              
    248      14    12824       8236       2.30  16148   2 1Password                                                                                                                                                                                              
    945      28    96832      10952      12.23  28976   2 1Password                                                                                                                                                                                              
    245      16     7208       6428       1.58  17304   2 1Password-BrowserSupport                                                                                                                                                                               
   1043      51    64340      29144             28080   0 Agent                                                                                                                                                                                                  



Sunday, May 7, 2023 7:27:11 PM


Script end!