Function New-DebugMessage { Param([string]$text) # build a text string of information that can be passed # to different pipelines like Debug #here are some variables you might want to work with $computer=$env:computername $domain=$env:userdomain $user=$env:username $timestamp=(Get-Date -Format g).toString() $line=$($myinvocation.scriptlinenumber) $script=$($myinvocation.invocationname) [string]$msg="[{0}:{1}\{2}] {3} Line:{4} {5}" -f $computer,$domain,$user,$timestamp,$line,$text write $msg } #sample usage #$debugpreference="continue" #Write-Debug (New-DebugMessage "starting $($myinvocation.invocationname)") #Write-Debug (New-DebugMessage "Getting Date") #Get-Date