-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathOut-LogHost.ps1
61 lines (48 loc) · 1.06 KB
/
Out-LogHost.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
filter Out-LogHost{
param(
[string]
$logfile,
[switch]
$message,
[switch]
$showdata,
[switch]
$hidedata,
[switch]
$error
)
if($message)
{
Write-Host "$_`n" -ForegroundColor Cyan
"[$(Get-Date)][message][$_]" | Out-File $logfile -Encoding utf8 -Append -Width 1024
}
elseif($showdata)
{
$_
$_ | Out-File $logfile -Encoding utf8 -Append -Width 1024
}
elseif($hidedata)
{
$_ | Out-File $logfile -Encoding utf8 -Append -Width 1024
}
elseif($error)
{
$_ | Out-File $logfile -Encoding utf8 -Append -Width 1024
throw $_
}
}
$log = "d:\message.log"
"hogehoge" | Out-LogHost -logfile $log -message
$log = "d:\hidedata.log"
ps | select -First 1 | Out-LogHost -logfile $log -hidedata
$log = "d:\showdata.log"
ps | select -First 1 | Out-LogHost -logfile $log -showdata
$log = "d:\error.log"
try
{
ps -Name hoge -ErrorAction Stop
}
catch
{
$_ | Out-LogHost -logfile $log -error
}