-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStop-AllTranscripts.ps1
50 lines (48 loc) · 1.35 KB
/
Stop-AllTranscripts.ps1
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
38
39
40
41
42
43
44
45
46
47
48
49
50
function Stop-AllTranscripts {
<#
.SYNOPSIS
Stop all transcripts
.DESCRIPTION
Stop all active PowerShell transcripts
.NOTES
File name: Stop-AllTranscripts.ps1
Author: Florian Carrier
Creation date: 2021-10-28
Last modified: 2021-10-28
#>
[CmdLetBinding ()]
Param (
[Parameter (
HelpMessage = "Suppress summary output"
)]
[Switch]
$Silent
)
Begin {
# Get global preference vrariables
Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
}
Process {
# Variables
$ActiveTranscript = $true
$Count = 0
# Stop transcripts
while ($ActiveTranscript) {
try {
Stop-Transcript
$Count += 1
} catch {
$ActiveTranscript = $false
}
}
# Generate log
if ($Silent -eq $false) {
switch ($Count) {
0 { return "The host is not currently transcribing." }
1 { $Log = "One single transcript was stopped." }
default { $Log = "$Count transcripts were stopped." }
}
Write-Log -Type "DEBUG" -Message $Log
}
}
}