mikaelsnavy
11/29/2017 - 6:47 PM

PowerShell Logging

#requires -runasadministrator 
 
New-EventLog -LogName PSScriptLog -Source Logon, Installation, Misc, Secret
Limit-EventLog -LogName PSScriptLog -MaximumSize 10MB -OverflowAction OverwriteAsNeeded

#or 

Write-EventLog -LogName PSScriptLog -Source Logon -EntryType Warning -EventId 123 -Message "Problem in script $PSCommandPath"
# add this: ############################ 
$logFile = "$PSScriptRoot\mylog.txt"
Start-Transcript -Path $logFile -Append
######################################### 
 
"Hello" 
 
($a = Get-Service)
 
"I received $($a.Count) services."
Write-Host "Watch out: direct output will not be logged!"
 
 
# end logging ########################### 
Stop-Transcript 
#########################################po