forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrite-Detail.ps1
More file actions
73 lines (65 loc) · 2.03 KB
/
Write-Detail.ps1
File metadata and controls
73 lines (65 loc) · 2.03 KB
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
Function Write-Detail {
[cmdletbinding(DefaultParameterSetName = "Default")]
Param(
[Parameter(Position = 0, Mandatory)]
[Parameter(ParameterSetName = "Default")]
[Parameter(ParameterSetName = "Date")]
[Parameter(ParameterSetName = "Time")]
[ValidateNotNullorEmpty()]
[string]$Message,
[Parameter(ParameterSetName = "Default")]
[Parameter(ParameterSetName = "Date")]
[Parameter(ParameterSetName = "Time")]
[string]$Prefix = "PROCESS",
[Parameter(ParameterSetName = "Date")]
[switch]$Date,
[Parameter(ParameterSetName = "Time")]
[Switch]$Time
)
#$pfx = $($Prefix.ToUpper()).PadRight("process".length)
if ($time) {
$dt = (Get-Date -Format "hh:mm:ss:ffff")
}
elseif ($Date) {
$dt = "{0} {1}" -f (Get-Date).ToShortDateString(), (Get-Date -Format "hh:mm:ss")
}
if ($PSCmdlet.ParameterSetName -eq 'Default') {
$Text = "[$($prefix.ToUpper())] $Message"
}
else {
$Text = "$dt [$($prefix.toUpper())] $Message"
}
$Text
} #close Write-Detail
Function Out-VerboseTee {
[CmdletBinding()]
[alias("tee-verbose")]
Param(
[Parameter(Mandatory, ValueFromPipeline)]
[object]$Value,
[Parameter(Position = 0, Mandatory)]
[string]$Path,
[System.Text.Encoding]$Encoding,
[switch]$Append
)
Begin {
#turn on verbose pipeline since if you are running this command you intend for it to be on
$VerbosePreference = "continue"
}
Process {
#only run if Verbose is turned on
if ($VerbosePreference -eq "continue") {
$Value | Out-String | Write-Verbose
$PSBoundParameters.Remove("Append") | Out-Null
if ($Append) {
Add-Content @PSBoundParameters
}
else {
Set-Content @PSBoundParameters
}
}
}
End {
$VerbosePreference = "silentlycontinue"
}
} #close Out-VerboseTee