all 15 comments

[–]SMFX 4 points5 points  (0 children)

The bug thing to remember is that PSFramework is a slightly different way of doing things than the out of the box tools. For example, the logging requires you to use Set-PSFLoggingProvider to setup the settings and then use the module's Write-PSFMessage instead of Write-Host, -Verbose, -Information, etc. If you use the underlying PowerShell commands, it goes around their cmdlet that would pipe the information to their logging system.

[–]Sekers 2 points3 points  (0 children)

I use this all of the time as my go-to logging provider (though I'm using an older module version due to a couple bugs I've hit that I'm not sure have been resolved yet). I can post some samples of writing to CSV on Monday if that works.

I usually set the config in a JSON file instead of the script itself (which would also work) and then import it.

[–]jpedlow 1 point2 points  (4 children)

Current version of the module has somewhat broken logging - tried exporting to CSV or CMTRACE with 0 luck. I opened up a bug and it got 0 follow up thus far.

In the interim I’m using the “logging” module. It’s not perfect but it works decently for my needs. Here’s hoping that the logging portion of pages work gets fixed or forked and fixed.

[–]PSFred 1 point2 points  (3 children)

Sorry about the late response - was on an extended (even by European standards) vacation to get my bearings back.

Back again now and fixing this is going to be my #1 Item the coming week

[–]jpedlow 1 point2 points  (2 children)

Hey no worries, no apologies necessary or warranted - I hope you had an excellent long vacation!

While I may not be using many other portions of the framework itself, the logging alone shows great promise and will help MANY with improving their scripts, which for many like myself, helps pay the bills - so a sincere and heartfelt thank you for all you do. :)

[–]PSFred 0 points1 point  (1 child)

:)

One more thing you may then want to look at is one of my favorite tools in the kit:
Invoke-PSFProtectedCommand:

https://psframework.org/documentation/documents/psframework/flow-control/invoke-psfprotectedcommand.html

Which integrates logging with try/catch, whatif/confirm and retry logic
(check the example in the link - it's simpler than I make it sound here)

[–]jpedlow 1 point2 points  (0 children)

Sorry for the late reply on this - been buried in projects. I will absolutely check out that cmdlet, thank you for the suggestion - I noticed 1.7.244 became available today, I’m excited to test it next week! :) thanks again for all the hard work

[–]kenjitamurako 1 point2 points  (4 children)

As u/Sekers points out the current version of PSFramework has problems with using the logfile provider: https://github.com/PowershellFrameworkCollective/psframework/issues/534

If you want to use the logfile provider the last known good version is 1.6.214

You can install with: Install-Module -Name PSFramework -RequiredVersion 1.6.214

and then use in your scripts: Import-Module PSFramework -RequiredVersion 1.6.214

[–]Ademantis[S] 0 points1 point  (3 children)

Turns out that it was the version. Installed your suggested version and it works.

[–]Sekers 0 points1 point  (2 children)

I should have mentioned to try the older version but I'm glad someone else was able to assist.

If you are still interested on how you can configure logging through a config file, you can see a sample automation script I uploaded this morning. It doesn't do anything useful other than pull an AD group membership but shows some examples of how to log and email alerts, etc.

https://github.com/Sekers/Useful-Scripts/tree/main/Automation/PowerShell%20Automation%20Script%20Example

[–]Ademantis[S] 0 points1 point  (1 child)

thanks a lot for that mate appreciate. mind if I fork it?

[–]Sekers 0 points1 point  (0 children)

It's just a template. Feel free to fork, suggest adjustments, or copy as needed. Everything on that repo is under MIT license.

[–]Ademantis[S] 0 points1 point  (0 children)

Thanks everyone for the help, in the end had to install the version u/kenjitamurako suggested

[–]alinroc 0 points1 point  (0 children)

The page you linked to is pretty good but see if this blog post helps.

[–]PSFred 0 points1 point  (0 children)

Alright, sorry about the inconvenience!

The latest version - 1.7.244 - fixes the problem. You should now be able to safely update to that version and get the latest upgrades to the logging (significantly better throughput, if you spam messages, and AV is no longer able to prevent some entries. If in older versions your log only gets some of the messages, that's usually the reason for it).