Skip to content

kirsh1793/KRA-PowerShell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Welcome

This repository contains my script template, my multi-environment profile script and my logging module. Some redditor asked me for the profile script, so I cleaned out company specific information as best as possible and uploaded it. It heavily makes use of my logging module, so I added that as well. The script template is very similar to the profile, which is why I added that, too.

Profile Script

Make sure to carefully read through both the config and the script. I might have made some mistakes during the cleanup that could break things. Just set everything up for your environment and test the script. Also assure you have my logging module installed. It's not in the PSGallery, but you can just copy the 'KRA.Logging' folder from 'Modules' into a module path on your system (e.g. C:\Users[YourUser]\Documents\WindowsPowerShell\Modules').

Template Script

Like my profile script, the template consists of a .psd1 config file and the actual .ps1 script file. The config can be used to define runtime constants and by deault it configures PSDefaultParameterValues for my logging module. The config allows you to set different values for a DEV and PRD environment and when calling the script, you can specify which environment should be used - default is PRD. The script also has parameters to override LogToConsole and NoLogFile values set in the config. There is a LogLevelOverride parameter that will override the script environment specific LogLevel (by default 0 for PRD and 9 for DEV).

KRA.Logging - my Logging Module

This is the module that started my module development journey at the end of 2022. Its main cmdlet 'Write-Log' is built to write log messages to files in CMTrace format or in a more simple format delimited by ';'. However, a few of the cmdlets only support CMTrace format - such as 'Read-CmTraceLog'. In 2025 I finally wrote a C# library to handle the log objects for this module. It mainly helps with performance when reading in large log files and also was my way to venture into C# development for PS modules. Some notable features include:

  • Logging in CMTrace format
  • Parsing CMTrace logs to a list of custom LogObjects with these properties:
    • Message (the actual log message)
    • LocalTime (timestamp in local time)
    • UtcTime (timestamp in UTC time)
    • UtcOffset (offset between local and UTC time)
    • Component (the command or CallStack component that triggered the log message)
    • Context (executing user)
    • Severity (a value from Ok, Info, Warning, Error)
    • LogLevel (if the LogLevel set in the current session is higher than the object's LogLevel, it will be shown/logged)
    • TID (Thread ID)
    • Source (CMTrace's source)
    • LogFile (filepath from where the object was parsed)
  • Single or multi file log infrastructure with cleanup based on file size (single file), or file age (multi file) or number of files (multi file)

About

Contains my multi environment profile script, my script template, and my logging module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published