< Back
Write-Message
Post
NAME Write-Message
SYNOPSIS
Handle message events in a script
SYNTAX
Write-Message [-Message] <String> [-MessageType] <String> [[-WriteLog] <String>] [-WriteEvent] [[-Source]
<String>] [-WriteToHost] [-CloseOnError] [-CloseOnSuccess] [[-EventID] <Int32>] [<CommonParameters>]
DESCRIPTION
Write log files, event logs, host messages and perform a specfic task based on the type of message
PARAMETERS
-Message <String>
The message that is to be written
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-MessageType <String>
The type of message, Valid types Error Warning Information and SuccessAudit
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WriteLog <String>
Path to log file, if not specified no messages will be written to a log
Writes the log in a csv format
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WriteEvent [<SwitchParameter>]
Writes the message to the application event log
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-Source <String>
Specifies where the event was created from, if not specified will default to MosaicMK Message Handling
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WriteToHost [<SwitchParameter>]
Writes the message to the PowerShell host
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-CloseOnError [<SwitchParameter>]
When an error message type is written the script will exit
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-CloseOnSuccess [<SwitchParameter>]
When a SuccessAudit message type is written the script will exit
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-EventID <Int32>
The event number that will be written to the log file, Event log and used as an exit code when
exit 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
Required? false
Position? 5
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
A function for each message type is present so addition tasks can be competed when a message of a specific
type is written.
Copyright (C) MosaicMK Software LLC - All Rights Reserved
Unauthorized copying of this application via any medium is strictly prohibited Proprietary and confidential
Written by MosaicMK Software LLC (contact@mosaicmk.com)
By using this software you agree to the following:
Agreement Permission is hereby granted, free of charge, to any person or organization obtaining a copy of this
software and associated documentation files (the "Software"),
to deal in the Software and the rights to use and distribute the software so long a no licensing and or
documentation files are remove, revised or modified
the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
Contact: Contact@MosaicMK.com
Version 1.1.0
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Write-Message -Message "Starting Proccess" -MessageType Information -WriteLog C:\\Logs\\proccess.log
-WriteEvent -WriteToHost
Writes the message 'Starting Proccess' to the proccess.log file, The Event log and to the PowerShell host window
as a Information message type
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Write-Message -Message "Starting Proccess" -MessageType Warning -WriteToHost
Writes the message 'Starting Proccess' to the PowerShell host window as a warning message type
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Write-Message -Message "Could not stop proccess" -MessageType Error -WriteEvent -CloseOnError -EventID 500
Writes the message to the event log then closes exits the script with event id 500
RELATED LINKS
https://www.mosaicmk.com
SYNOPSIS
Handle message events in a script
SYNTAX
Write-Message [-Message] <String> [-MessageType] <String> [[-WriteLog] <String>] [-WriteEvent] [[-Source]
<String>] [-WriteToHost] [-CloseOnError] [-CloseOnSuccess] [[-EventID] <Int32>] [<CommonParameters>]
DESCRIPTION
Write log files, event logs, host messages and perform a specfic task based on the type of message
PARAMETERS
-Message <String>
The message that is to be written
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-MessageType <String>
The type of message, Valid types Error Warning Information and SuccessAudit
Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WriteLog <String>
Path to log file, if not specified no messages will be written to a log
Writes the log in a csv format
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WriteEvent [<SwitchParameter>]
Writes the message to the application event log
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-Source <String>
Specifies where the event was created from, if not specified will default to MosaicMK Message Handling
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WriteToHost [<SwitchParameter>]
Writes the message to the PowerShell host
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-CloseOnError [<SwitchParameter>]
When an error message type is written the script will exit
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-CloseOnSuccess [<SwitchParameter>]
When a SuccessAudit message type is written the script will exit
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-EventID <Int32>
The event number that will be written to the log file, Event log and used as an exit code when
exit 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
Required? false
Position? 5
Default value 0
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
A function for each message type is present so addition tasks can be competed when a message of a specific
type is written.
Copyright (C) MosaicMK Software LLC - All Rights Reserved
Unauthorized copying of this application via any medium is strictly prohibited Proprietary and confidential
Written by MosaicMK Software LLC (contact@mosaicmk.com)
By using this software you agree to the following:
Agreement Permission is hereby granted, free of charge, to any person or organization obtaining a copy of this
software and associated documentation files (the "Software"),
to deal in the Software and the rights to use and distribute the software so long a no licensing and or
documentation files are remove, revised or modified
the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
Contact: Contact@MosaicMK.com
Version 1.1.0
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Write-Message -Message "Starting Proccess" -MessageType Information -WriteLog C:\\Logs\\proccess.log
-WriteEvent -WriteToHost
Writes the message 'Starting Proccess' to the proccess.log file, The Event log and to the PowerShell host window
as a Information message type
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Write-Message -Message "Starting Proccess" -MessageType Warning -WriteToHost
Writes the message 'Starting Proccess' to the PowerShell host window as a warning message type
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Write-Message -Message "Could not stop proccess" -MessageType Error -WriteEvent -CloseOnError -EventID 500
Writes the message to the event log then closes exits the script with event id 500
RELATED LINKS
https://www.mosaicmk.com