Private/Log-Message.ps1
function Log-Message { <# .SYNOPSIS Logs a message to the console with a specified text colour and appends the same message to a log file. .DESCRIPTION The Log-Message function provides a convenient way to log messages in PowerShell scripts and modules. It allows you to specify a message and an optional text colour for display in the console. Additionally, the function appends the message, along with a timestamp, to a log file for further analysis and auditing. .PARAMETER Message Specifies the message to be logged. This parameter is mandatory. .PARAMETER Color Specifies the text colour for displaying the message in the console. Valid values are any ConsoleColour names (e.g., "Red", "Green", "Yellow", etc.). Default value is "White". .EXAMPLE Log-Message -Message "Task completed successfully!" -Color "Green" Logs a success message in green color to the console and appends the message to the log file. .EXAMPLE Log-Message -Message "Error occurred: Unable to process the request." Logs an error message in default white color to the console and appends the message to the log file. .NOTES Version : 1.0 #> param ( [Parameter(Mandatory = $true)] [string]$Message, [Parameter(Mandatory = $false)] [string]$Color = "White" ) Write-Host $Message -ForegroundColor $Color Add-Content -Path "C:\ProgramData\Intune-PowerShell-Logs\TeamViewerManagedDevice.log" -Value "$(Get-Date) - $Message" } |