#Install the Log4net based module for All users (Requires administrator rights on the machine) 
Install-Module -Name OSCCPSLogging -Scope AllUsers 
#Alternatively install the Log4net based module for the current user 
Install-Module -Name OSCCPSLogging -Scope CurrentUser 
#Getting to know the module / read the help 
get-command -module OSCCPSLogging 
get-help Initialize-CMLogging 
get-help Initialize-CMLogging -Examples 
get-help Out-Loginfo -Examples 
#start logging 
$log = Initialize-CMLogging  
Out-LogInfo $log "logging informational message" 
Out-LogWarn $log "logging warning message"  
Out-LogError $log "logging error message"  
Out-LogDebug $log "logging debug message" 

This contribution describes a PowerShell module that eases logging in PowerShell scripts. I've built the module in an attempt to make me add logging to my scripts right out of the gate, as opposed to the more common behaviour, of adding logging as an after thought.

There are quite a few logging functions out there, but upon investigation I noticed that in the .Net and Java world Log4J and Log4Net seemed to have quite a large set of followers. So I set forth to use Log4Net in Powershell and make it's usage as easy as possible.

Log4Net has a large number of followers, largely because it is a hugely flexible framework that allows logging to file, console, SMTP, database, Event viewer etc...

The logging module wraps the log4net dll's, and adds an extension to log4net to ease logging in the CMTrace format that is fairly popular, at least in the System Center Configuration Manager world.


The module is published in the PowerShell gallery, so installation couldn't be easier.

PowerShell 3.0 & 4.0

To install the module in PowerShell versions lower as 5.0 you need to install the package Provider prior to installing the module. You can find the MSI to do this at