< Back
Write-Log
Post
NAME Write-Log
SYNOPSIS
Write to the log.
SYNTAX
Write-Log [[-LogEntry] <String>] [-LogType <String>] [-EventID <String>] [-Log <Object>] [-PassThru]
[<CommonParameters>]
DESCRIPTION
The Write-Log function is used to write to the log. It is using the log object created by New-Log
to determine if it's going to write to a log file or to a Windows Event log.
PARAMETERS
-LogEntry <String>
The text you want to write to the log.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-LogType <String>
The type of log entry. Valid choices are 'Error', 'FailureAudit','Information','SuccessAudit' and 'Warning'.
Note that the CMTrace format only supports 3 log types (1-3), so 'Error' and 'FailureAudit' are translated to
CMTrace log type 3, 'Information' and 'SuccessAudit'
are translated to 1, while 'Warning' is translated to 2. 'FailureAudit' and 'SuccessAudit' are only really
included since they are valid log types when
writing to the Windows Event Log.
Required? false
Position? named
Default value Information
Accept pipeline input? false
Accept wildcard characters? false
-EventID <String>
Event ID. Only applicable when writing to the Windows Event Log.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Log <Object>
The log object created using the New-Log function. Defaults to reading the global PSLOG variable.
Required? false
Position? named
Default value $global:PSLOG
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-PassThru [<SwitchParameter>]
PassThru passes the log entry to the pipeline for further processing.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Author: ????????yvind Kallstad
Date: 21.11.2014
Version: 1.0
Dependencies: Invoke-LogRotation
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Write-Log 'Finished running WMI query'
Get the log object from $global:PSLOG and write to the log.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$myLog | Write-Log 'Finished running WMI query'
Use the log object saved in $myLog and write to the log.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Write-Log 'WMI query failed - Access denied!' -LogType Error -PassThru | Write-Warning
Will write an error to the event log, and then pass the log entry to the Write-Warning cmdlet.
RELATED LINKS
SYNOPSIS
Write to the log.
SYNTAX
Write-Log [[-LogEntry] <String>] [-LogType <String>] [-EventID <String>] [-Log <Object>] [-PassThru]
[<CommonParameters>]
DESCRIPTION
The Write-Log function is used to write to the log. It is using the log object created by New-Log
to determine if it's going to write to a log file or to a Windows Event log.
PARAMETERS
-LogEntry <String>
The text you want to write to the log.
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-LogType <String>
The type of log entry. Valid choices are 'Error', 'FailureAudit','Information','SuccessAudit' and 'Warning'.
Note that the CMTrace format only supports 3 log types (1-3), so 'Error' and 'FailureAudit' are translated to
CMTrace log type 3, 'Information' and 'SuccessAudit'
are translated to 1, while 'Warning' is translated to 2. 'FailureAudit' and 'SuccessAudit' are only really
included since they are valid log types when
writing to the Windows Event Log.
Required? false
Position? named
Default value Information
Accept pipeline input? false
Accept wildcard characters? false
-EventID <String>
Event ID. Only applicable when writing to the Windows Event Log.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Log <Object>
The log object created using the New-Log function. Defaults to reading the global PSLOG variable.
Required? false
Position? named
Default value $global:PSLOG
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-PassThru [<SwitchParameter>]
PassThru passes the log entry to the pipeline for further processing.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Author: ????????yvind Kallstad
Date: 21.11.2014
Version: 1.0
Dependencies: Invoke-LogRotation
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Write-Log 'Finished running WMI query'
Get the log object from $global:PSLOG and write to the log.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>$myLog | Write-Log 'Finished running WMI query'
Use the log object saved in $myLog and write to the log.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Write-Log 'WMI query failed - Access denied!' -LogType Error -PassThru | Write-Warning
Will write an error to the event log, and then pass the log entry to the Write-Warning cmdlet.
RELATED LINKS