Looking for a log4j style logging module

I’m currently using a combination of Start-Transcript, Write-Host, Write-Output but would like to move on to using a more standardized and robust log4j style logging module that I can simply import into any script.

In Perl, my main language, I use its very robust Log::Log4perl module which is perl’s implementation of java’s log4j. I’ve done a little googling and have found a couple options but the examples that I found weren’t very extensive. What is the best logging module available for powershell?

What is the best logging module available for powershell?
That's pretty much a matter of taste I think. I like to use the logging format of SCCM because I like the log viewer (cmtrace.exe) pretty much. You could get a bunch of opportunities with:
Find-Module *logging*
... I did not try it yet but the description for the OSCCPSLogging sounds neat. ;-)

Thanks for the suggestion. I’ll take a look at OSCCPSLogging.

The search command failed.

PS C:> find-module logging
find-module : The term ‘find-module’ is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.

I recommend to update either your Powershell version or your Windows version (incl. Powershell) to the newest one. Just because I’m curious - what version of Windows and Powershell do you use?

The install instructions is failing for me.

PS C:\> Install-Module -Name OSCCPSLogging -RequiredVersion 1.5.0.1 Install-Module : The term 'Install-Module' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS C:\> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

Most of our stations are Win7 pro with a limited number of 8.1 tablets. Upgrading to 10 is a no go due to licensing cost for 4000+ stations.

Ah … ok. So probably this cmdlet came with version 5 or 5.1. But at least the module OSCCPSLogging runs with version 3 - you just have to install it manually. :wink:

Installing it manually is going to be a problem.

The script I’m working on is a startup script launched during bootup via group policy and is used to join the station to our Samba4 domain.

However, if the module installation could be automated, then I can install it from my other program (written in another language) which runs only once to install this script and initialize the group policy files and registry entries.

Wow … do you really need logging for a startup script? That sounds very unusual to me.
Regardles of that most slightly large Windows environments use a kind of software deployment infrastructure. If you have something like that in place you still could use this to install the module if you really need to.

You need to install PowerSHellGet to do what Olaf is saying.
PoSHGet comes with Win10, WS2016 previous OS versions need to download and install it.

PackageManagement PowerShell Modules Preview - March 2016
microsoft.com/en-us/download/details.aspx?id=51451

Supported Operating System

Windows 7 Service Pack 1, Windows 8.1, Windows Server 2008 R2 SP1, Windows Server 2012, Windows Server 2012 R2
•Windows Server 2012 R2
•Windows 8.1 Pro
•Windows 8.1 Enterprise
•Windows Server 2012
•Windows 7 SP1
•Windows Server 2008 R2 SP1

docs.microsoft.com/en-us/powershell/module/powershellget/?view=powershell-5.1

If you are on WS2008R2 or higher, Enable PowerShell logging via GPO for the domain.

How to Enable PowerShell Logging | Petri IT Knowledgebase

Or use

Start-Transcript/End-Transcript cmdlets

We don’t have any WS2008R2 systems on the domain. Currently we only have Win7 pro and Win8.1.

Our current logging is being handled via Start-Transcript/End-Transcript cmdlets but IMO, that is not good enough for my needs. I want better control over the logging format without having to write my own wrapper functions around Start-Transcript/End-Transcript.

Our startup script does a lot more than setting the registry keys/values to join the domain. The current script was written by someone else in our dept who did not know powershell and is more of a “script kiddie”. The code is very messy and has almost no error checking/handing and because of the way it was coded (logic and formatting), it is very difficult to troubleshoot the numerous bugs that it currently has which are causing it to fail often. I am in the process of rewriting it from scratch and adding extra logging to aid in the troubleshooting.

Going back to the topic of logging, it’s looking like OSCCPSLogging will require jumping through lots of extra coding hoops to be able to automate the install, so it may not be the best choice for my needs.

Are there any other options you can think of that would be a more straight forward and relatively simple module install to provide log4j style logging?

BTW, My logging needs is not limited to this startup script. If it was, I would stay with the current logging method.

Obviously I have a completely other concecpt in mind when I hear “startup script”. For me something like this would never have a “domain join” in it. It runs when a computer starts or when a user logs in. :wink:
So you’re asking for a log4j like logging but you’re refusing to spend the effort for it. As far as I understood is the original log4j a framework as well and needs some effort to use in the first place. I don’t know log4j and its capabilities. What are your logging needs?

I don’t mind spending the effort, but I also don’t think having to write my own installation framework to automate the install of a logging framework.

To give you an idea of the logging capabilities I’m looking for you can look at the Log::Log4perl module I use, which I can install with 1 very simple command.
cpanm install Log::Log4perl

I need to take a closer look but the powershell solution I’m looking for might be the Apache log4net library.

If you would have a current version of Windows and Powershell the cmdlet to install the module would be “Install-Module OSCCPSLogging”. So IMHO it’s a little unfair to complain about that. :wink:
But my question actually was about what you expect the logging should do for you. What do you expect it to do? If you simply want to log a message to a file you could use Out-File. There’s nothing more simple then that I think.
And BTW: the module we’re talking about is based on log4net!! :wink:

I’m not complaining. I’m just trying to find a reasonable solution given the OS and PS version limitations I’m dealing with.

Would you like to supply the money to upgrade or replace 4000+ computers to Win10?

Would you like to supply the money to upgrade or replace 4000+ computers to Win10?
If I had ... of course ... sure ... always. :-D

It doesn’t appear that MS (or maybe just the author of OSCCPSLogging) isn’t concerned about backwards compatibility, otherwise they would have provided another method to install it.

It doesn't appear that MS (or maybe just the author of OSCCPSLogging) isn't concerned about backwards compatibility, otherwise they would have provided another method to install it.

Don’t you have access to a Windows 10 where you could install / download the module? Once you have the files you can do whatever you need. You could even “include” it into your startup script by simply importing it from a file share.