-
-
Notifications
You must be signed in to change notification settings - Fork 274
/
Start-Logging.psm1
34 lines (29 loc) · 896 Bytes
/
Start-Logging.psm1
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
Import-Module -DisableNameChecking "$PSScriptRoot\Get-TempScriptFolder.psm1"
function Start-Logging() {
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Position = 0)]
[String] $Path = "$(Get-TempScriptFolder)\logs",
[Parameter(Position = 1, Mandatory)]
[String] $File
)
Begin {
$File = "$File.log"
}
Process {
Write-Host -NoNewline "[@] " -ForegroundColor Blue
Start-Transcript -Path "$Path\$File" -Append
Write-Host
}
}
function Stop-Logging() {
Write-Host -NoNewline "[@] " -ForegroundColor Blue
Stop-Transcript
Write-Host
}
<#
Example:
Start-Logging -File (Split-Path -Path $PSCommandPath -Leaf).Split(".")[0]
Start-Logging -Path "$env:TEMP\Win-Debloat-Tools\logs" -File "WingetDailyUpgrade" # Automatically uses .log format
Stop-Logging # Only after logging has started
#>