summaryrefslogtreecommitdiff
path: root/userphotos/loglib.ps1
blob: 92a5f40de3e82c97111eb16252a96a29e20313a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Filename: \\util201\scripts\Functions\loglib.ps1
# License: CC-BY-SA 4.0
# Author: bgstack15, TAFKAC
# Startdate: 2019-11-25 10:19
# Title: Logging library
# Purpose: Provide logging functions
# History: 
# Usage:
# Reference:
#    internal file systems-engineering/powershell/deploy-server/iad/library/functions.ps1
# Improve:
# Dependencies:
#

### GLOBAL VARIABLES
$global:today = Get-Date -Format yyyy-MM-dd

### FUNCTIONS
Function Log {
	# adapted from TAFKAC
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $TRUE, Position = 0)]
        [string] $entry
    ) 
    If (!($GLOBAL:log -ne $NULL)) {
        Set-Variable -Name log -Value @() -Scope Global;
    }
    $stamp = (Get-Date -Format FileDateTimeUniversal);
    $GLOBAL:log += "[$stamp] $entry";
    Write-Host "[$stamp] $entry" -ForegroundColor Gray
	if ($global:logfile -ne $null)
	{
		$logid = ""; if ($global:logid -ne $null) {$logid = " ${global:logid}"}
		"[$stamp] ${env:UserName}@${env:ComputerName}${logid}: $entry" | Out-File -Append $global:logfile
	}
}
bgstack15