Message Handling - V 1.0.0

 Message Handling is PowerShell Module designed to write a message to a log file, Event log or PowerShell host window and provide the ability to perform a task based on the message type.

The Module can be imported and will provide a Write-Message function. The Write-Message function can also be used as a standalone PowerShell script. The idea of the Write-Message command is to write an Error, Warning, Information or Success message to a desired forum and perform an action based on the message type.


The module is designed to be flexible to fit most needs. To perform an action based on the message type there are 4 internal functions Invoke-Error, Invoke-Warning, Invoke-information and Invoke-SuccessAudit. Code can be added to each function to additions task will be performed when a message of that type is written.


The command requires that at least one of the write parameters (WriteLog, WriteEvent, WriteToHost) is specified for the script to actually do anything. Each will write the message to its corresponding forum for example:


This will write the information message to the C:\logs\script.log file

Parameters 


  • Message
    • <String>
    • The message that is to be written
  • MessageType
    • <String>
    • The type of message, Valid types Error Warning Information and SuccessAudit
    • Valid Types
      • Error
      • Warning
      • Information
      • SuccessAudit
  • WriteLog
    • Type <String>
    • Path to log file, if not specified no messages will be written to a log
    • The log is written in csv format
  • WriteEvent
    • Type <Switch>
    • Writes the message to the application event log
  • Source
    • <String>
    • Specifies where the event was created from, if not specified will default to MosaicMK Message Handling
  • WriteToHost
    • Type <Switch>
    • Writes the message to the PowerShell host
  • CloseOnError
    • Type <Switch>
    • When an error message type is written the script will exit
  • CloseOnSuccess
    • Type <Switch>
    • When a SuccessAudit message type is written the script will exit
  • EventID
    • Type <Int32>
    • The event number that will be written to the log file, Event log and used as an exit code when CloseOnError or CloseOnSuccess is used.
    • If not specified the script will default the Event ID to the following:
      • Error = 1
      • Warning = 2
      • Information = 100
      • SuccessAudit = 0
The Script Can be downloaded from our PowerShell Gallery Page



Comments

Popular posts from this blog

SCCM Task Sequence GUI - How to set up the TS to work with a GUI

SCCM Applications vs. SCCM Packages: Understanding the Key Differences

Windows 10 Setup Script - Version 2.5.0.1