Logger.psm1
$script:Logname = "TurnKeySdn-$(get-date -Format 'yyyyMMdd-HHmmss').log" $script:LogDirectory = "$env:SystemDrive\Windows\Tracing\TurnKeySdn" $script:LogFile = Join-Path $script:LogDirectory $script:Logname function Write-TraceLog { Param( [Parameter(Position = 0)] [String] $Message, [switch] $Chatty, [switch] $Info, [switch] $Warning, [switch] $Err ) $FormattedDate = date -Format "yyyyMMdd-HH:mm:ss" $FormattedMessage = "[$FormattedDate] $Message" if ($Chatty.IsPresent) { Write-Verbose $FormattedMessage } elseif ($Info.IsPresent) { Write-Host $FormattedMessage } elseif ($Warning.IsPresent) { Write-Host $FormattedMessage -ForegroundColor Cyan } elseif ($Err.IsPresent) { Write-Host $FormattedMessage -ForegroundColor Red } else { Write-Host $FormattedMessage } if (-not (Test-Path $script:LogDirectory)) { New-Item $script:LogDirectory -ItemType Directory | Out-Null } $FormattedMessage | Out-File $script:LogFile -Append } function Write-FunctionEntryWithParams { Param( [String] $FunctionName, [Object] $BoundParameters, [String] $UnboundArguments, [object] $ParamSet ) Write-TraceLog -Message "Enter Function: $FunctionName" foreach ($param in $BoundParameters.keys) { if ($param.ToUpper().Contains("PASSWORD") -or $param.ToUpper().Contains("KEY")) { Write-TraceLog -Message " -$($param): ******" } else { $value = $BoundParameters[$param] Write-TraceLog -Message " $param $value " } } Write-TraceLog -Message "Unbound Arguments: $UnboundArguments" if( Test-Path variable:\pscmdlet) { if($null -ne $pscmdlet) { Write-TraceLog -Message "ParameterSet: $($paramset.ParameterSetName)" } } } |