Skip to content

Instantly share code, notes, and snippets.

@ploegert
Created June 9, 2015 14:25
Show Gist options
  • Select an option

  • Save ploegert/8fc7a0595a20542c6c51 to your computer and use it in GitHub Desktop.

Select an option

Save ploegert/8fc7a0595a20542c6c51 to your computer and use it in GitHub Desktop.
Utilities for logging.
<#
Utilities for logging.
NOTE: This module is used by the install script, which must run on PowerShell 2.0
Be sure to test any changes to this module using PS 2.0.
#>
Set-StrictMode -Version latest
$ErrorActionPreference = 'stop'
<#
.Synopsis
Returns the path of the file to which the extension's output should be redirected
#>
function Get-LogFile
{
$handlerEnvironment = Get-HandlerEnvironment
$sequenceNumber = Get-HandlerExecutionSequenceNumber
$timestamp = Get-Date -UFormat '%Y%m%d-%H%M%S'
'{0}\DscExtensionHandler.{1}.{2}.log' -f $handlerEnvironment.logFolder, $sequenceNumber, $timestamp
}
<#
.Synopsis
A simple wrapper around Write-Verbose that adds a timestamp
#>
function Write-Log
{
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
[AllowEmptyString()]
[string]
$Message
)
Write-Verbose -Verbose ("[{0:s}] {1}`r`n" -f (get-date), $Message)
}
Export-ModuleMember -Function Get-LogFile, Write-Log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment