Skip to content

Powershell Logging Module (for Event Log and Logfiles)

License

Notifications You must be signed in to change notification settings

kns7/KNSLogging

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

KNSLogging

Description

This Powershell module provide helpers functions for logging. It can manage a Log file or write to the Event Log.

List of CMDlets

Initialize-Log

Synopsis

Init log File.

Syntax

Initialize-Log [-LogFile] <String> [<CommonParameters>]

Parameters

Name Alias Description Required? Pipeline Input Default Value
LogFile System.String the path to the log file. true false
OutOnConsole System.Boolean Set for the whole module if the Log functions (Write-Log and Event-Log) should be outputted into the Console. false false

Examples

BEISPIEL 1

Initialize-Log -LogFile "C:\Logs\Test.log"

Rotate-Files

Synopsis

Clean up and rotate files

Syntax

Rotate-Files [-FilesDir] <String> [[-DayOfWeek] <Int32>] [[-DayOfMonth] <Int32>] [[-RotationDaily] <Int32>]
[[-RotationWeekly] <Int32>] [[-RotationMonthly] <Int32>] [<CommonParameters>]

Parameters

Name Alias Description Required? Pipeline Input Default Value
FilesDir true false
DayOfWeek Directory log files are written to false false 2
DayOfMonth The day of the week to store for weekly files (1 to 7 where 1 is Sunday) false false 1
RotationDaily The day of the month to store for monthly files (Max = 28 since varying last day of month not currently handled) false false 7
RotationWeekly The number of daily files to keep false false 6
RotationMonthly The number of weekly files to keep The number of monthly files to keep false false 5

Examples

BEISPIEL 1

Rotate-Logs -FilesDir "c:\MyFilesDirectory"

Write-EventLog

Synopsis

Write a new entry in Event Log

Syntax

Write-EventLog [-Source] <String> [-Message] <String> [[-Level] <String>] [<CommonParameters>]

Parameters

Name Alias Description Required? Pipeline Input Default Value
Source System.String. Required. The Source of the Event. true false
Message System.String. Required. The Message to put into Event log. true false
Level System.String. Optional. The Event Level. Valid Values are "Error", "Warning", "Information", "SuccessAudit" and "FailureAudit". Default value is "Information" false false Information

Examples

BEISPIEL 1

Write-EventLog -Source "ActiveDirectory" -Message "Everything's fine! Let's set back and relax"

Write-EventLog

Syntax

Write-EventLog [-LogName] <string> [-Source] <string> [-EventId] <int> [[-EntryType] <EventLogEntryType>] [-Message] <string> [-Category <int16>] [-RawData <byte[]>] [-ComputerName <string>] [<CommonParameters>]

Parameters

Name Alias Description Required? Pipeline Input Default Value
Category Keine false false
ComputerName CN false false
EntryType ET false false
EventId ID, EID true false
LogName LN true false
Message MSG true false
RawData RD false false
Source SRC true false

Links

Write-Log

Syntax

Write-Log writes a message to a specified log file with the current time stamp.

Parameters

Name Alias Description Required? Pipeline Input Default Value
Message LogContent System.String The Content to write in Logfile true true (ByPropertyName)
Level System.String The Log Level. Valid values are ERROR,WARN and INFO false true (ByPropertyName) Info
OutOnConsole Console System.Boolean If set to True, the log will also appear in the console. Default set to False false true (ByPropertyName) False
NoClobber NoClobber false false False

Outputs

  • System.Int32

Examples

BEISPIEL 1

Write-Log -Message "Log message"

Writes the message to c:\Logs\PowerShellLog.log

BEISPIEL 2

Write-Log -Message "Restarting Server" -Path c:\Logs\Scriptoutput.log

Writes the content to the specified log file and creates the path and file specified.

BEISPIEL 3

Write-Log -Message "Does not exist" -Path c:\Logs\Script.log -Level Error

Writes the message to the specified log file as an error message, and writes the message to the error pipeline.

About

Powershell Logging Module (for Event Log and Logfiles)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published