-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoaLoggingModule.psm1
45 lines (39 loc) · 1.46 KB
/
CoaLoggingModule.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
35
36
37
38
39
40
41
42
43
44
45
<#
.Synopsis
Logs the events of New and Set verbs to a file.
.Description
Changes happen with new or set verbs. This module logs those changes to a file.
.Parameter writeTo
Logs the event.
.Parameter logCode
Logs the COA custom status code: Success, Error
.Parameter FilePath
The location of the text log file. Include the last backslash when writing.
.Parameter FileName
The descriptive name of the log file. Do not include the file extenstion. It will be a .log.
.Example
# Write data to the log file
Add-CoaWriteToLog -writeTo "Logged an example line." -logCode "Success" -FilePath "\\Its01\deptfiles\Its\EmailTeam\Logs\" -FileName "exampleLog"
#>
function Add-CoaWriteToLog {
param(
[string]$writeTo,
[string]$logCode,
[string]$FilePath = "C:\Logs\",
[parameter(Mandatory = $true)][string]$FileName = "noNameLog"
)
$logLineTime = (Get-Date).ToString()
$logFileDate = Get-Date -UFormat "%Y%m%d"
$logLineInfo = "`t$([Environment]::UserName)`t$([Environment]::MachineName)`t"
$logLine = $null
$logLine = $logLineTime
$logLine += $logLineInfo
$logLine += $logCode; $logLine += "`t"
$logLine += $writeTo
$logLine | Out-File -FilePath "$FilePath$FileName`_$logFileDate.log" -Append -NoClobber
Clear-Variable logLine
Clear-Variable writeTo
Clear-Variable logLineTime
Clear-Variable logCode
}
Export-ModuleMember -Function Add-CoaWriteToLog