-
Notifications
You must be signed in to change notification settings - Fork 237
/
Get-NavContainerEventLog.ps1
48 lines (44 loc) · 1.91 KB
/
Get-NavContainerEventLog.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
<#
.Synopsis
Get the Event log from a NAV/BC Container as an .evtx file
.Description
Get a copy of the current Event Log from a continer and open it in the local event viewer
.Parameter containerName
Name of the container for which you want to get the Event log
.Parameter logName
Name of the log you want to get (default is Application)
.Parameter doNotOpen
Obtain a copy of the event log, but do not open the event log in the event viewer
.Example
Get-BcContainerEventLog -containerName bcserver
.Example
Get-BcContainerEventLog -containerName bcserver -logname Security -doNotOpen
#>
function Get-BcContainerEventLog {
[CmdletBinding()]
Param (
[string] $containerName = $bcContainerHelperConfig.defaultContainerName,
[Parameter(Mandatory=$false)]
[string] $logname = "Application",
[switch] $doNotOpen
)
Write-Host "Getting event log for $containername"
$eventLogFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "EventLogs"
if (!(Test-Path $eventLogFolder)) {
New-Item $eventLogFolder -ItemType Directory | Out-Null
}
$eventLogName = Join-Path $eventLogFolder ($containerName + ' ' + [DateTime]::Now.ToString("yyyy-MM-dd HH.mm.ss") + ".evtx")
$locale = (Get-WinSystemLocale).Name
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param([string]$path, [string]$logname, [string]$locale)
wevtutil epl $logname "$path"
wevtutil al "$path" /locale:$locale
} -ArgumentList (Get-BcContainerPath -containerName $containerName -Path $eventLogName), $logname, $locale
if ($doNotOpen) {
$eventLogName
}
else {
Start-Process -FilePath $eventLogName | Out-Null
}
}
Set-Alias -Name Get-NavContainerEventLog -Value Get-BcContainerEventLog
Export-ModuleMember -Function Get-BcContainerEventLog -Alias Get-NavContainerEventLog