Author Posts

January 31, 2018 at 4:23 pm

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?

January 31, 2018 at 8:22 pm

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. 😉

January 31, 2018 at 8:36 pm

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.

January 31, 2018 at 9:07 pm

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?

January 31, 2018 at 9:09 pm

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.

January 31, 2018 at 9:11 pm

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.

January 31, 2018 at 9:32 pm

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. 😉

January 31, 2018 at 9:46 pm

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.

January 31, 2018 at 11:15 pm

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.

January 31, 2018 at 11:47 pm

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'

January 31, 2018 at 11:50 pm

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

'petri.com/enable-powershell-logging'

Or use

Start-Transcript/End-Transcript cmdlets

February 1, 2018 at 12:41 am

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.

February 1, 2018 at 1:00 am

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.

February 1, 2018 at 10:20 am

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. 😉
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?

February 1, 2018 at 2:33 pm

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.

February 1, 2018 at 2:47 pm

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. 😉
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!! 😉

February 1, 2018 at 3:01 pm

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?

February 1, 2018 at 3:03 pm

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

If I had ... of course ... sure ... always. 😀

February 1, 2018 at 3:11 pm

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.

February 1, 2018 at 3:22 pm

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.

February 1, 2018 at 3:29 pm

Have you thought about downloading the module and putting it in a UNC path and then writing a script that puts it in say $EnvProgramFiles\WindowsPowerShell\Modules\\

Then in your startup script run "import-module"?

Installing a PowerShell Module

You don't need Win10 to run install-module, just PS 5.1 on your Win7 machine. If you can't get ps 5.1 installed, maybe email the author asking for a download of it somewhere?

February 1, 2018 at 3:47 pm

Have you thought about downloading the module and putting it in a UNC path and then writing a script that puts it in say $EnvProgramFiles\WindowsPowerShell\Modules\\

Then in your startup script run "import-module"?

Yes, that is what I'm now working on. I just downloaded log4net-2.0.8-bin-newkey.zip from logging.apache.org and am in the process of extracting the files.

February 1, 2018 at 3:53 pm

Yes, that is what I'm now working on. I just downloaded log4net-2.0.8-bin-newkey.zip from logging.apache.org and am in the process of extracting the files.

Why don't you download the Powershell module from the Gallery? It's just about 1.8 MB and ready to use in Powershell.

February 1, 2018 at 4:15 pm

That's what I was wanting to do but I have not been able to locate a download link. All I can find is the page that instructs you to use PS> Install-Module -Name OSCCPSLogging to install it. OSCCPSLogging 1.5.0.1

Do you know the url for downloading it?

February 1, 2018 at 4:47 pm

I just tested the example from this article PowerShell logging using Apache log4net and it was simple to implement and it worked exactly the way I want. So, I'll skip the OSCCPSLogging option.

February 1, 2018 at 8:59 pm

Great. I'm glad you finally found what you was looking for.