The GlobalFunctions PowerShell module has been updated to support the writing of log messages to the PowerShell output pipeline.
When writing to the PowerShell output pipeline, the severity level is not written to the pipeline. In most cases, you will use this option for debugging purposes.
Example
# Import module first Import-Module -Name GlobalFunctions # Create an instance of the logger $ScriptDir = Split-Path -Path $script:MyInvocation.MyCommand.Path $ScriptName = $MyInvocation.MyCommand.Name $logger = New-Logger -ScriptRoot $ScriptDir -ScriptName $ScriptName -LogFileRetention 14 # Write an informational message to the log file only $logger.Write('Some informational message') # Write an informational message to the log file only $logger.Write('Some message to log and console',0,$true) # Write a warning level message to log file and the message only to PowerShell output pipeline $logger.Write('Some warning message',2,$true)
Note
Remember to add the severity level when writing to the console.
Read more about the GlobalFunctions module here.
You can get the source code here:
- Import from PowerShellGallery: https://www.powershellgallery.com/packages/GlobalFunctions
- Download and follow at Github: https://github.com/Apoc70/GlobalFunctions