-
Notifications
You must be signed in to change notification settings - Fork 3
/
Stop-Timer.ps1
73 lines (59 loc) · 1.37 KB
/
Stop-Timer.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function Stop-Timer
{
<#
.SYNOPSIS
Function will halt a stopwatch.
.DESCRIPTION
Function requires a [System.Diagnostics.Stopwatch] object as input and will invoke the stop() method to hald its execution.
If no exceptions are returned function will return $True.
.PARAMETER Timer
A [System.Diagnostics.Stopwatch] representing the stopwatch to stop.
.EXAMPLE
PS C:\> Stop-Timer -Timer $Timer
.OUTPUTS
System.Boolean
#>
[OutputType([bool])]
param
(
[Parameter(Mandatory = $true)]
[System.Diagnostics.Stopwatch]$Timer
)
Begin
{
# Save current configuration
[string]$currentConfig = $ErrorActionPreference
# Update configuration
$ErrorActionPreference = 'Stop'
}
Process
{
try
{
# Stop timer
$Timer.Stop()
return $true
}
catch
{
# Save exception
[string]$reportedException = $Error[0].Exception.Message
Write-Warning -Message 'Exception reported while halting stopwatch - Use the -Verbose parameter for more details'
# Check we have an exception message
if ([string]::IsNullOrEmpty($reportedException) -eq $false)
{
Write-Verbose -Message $reportedException
}
else
{
Write-Verbose -Message 'No inner exception reported by Disconnect-AzureAD cmdlet'
}
return $false
}
}
End
{
# Revert back configuration
$ErrorActionPreference = $currentConfig
}
}