Skip to content

Commit 7db4317

Browse files
Merge pull request LabtechConsulting#40 from DarrenWhite99/Get-LTServiceInfo-Update
Fixes for Get-LTErrors and Get-LTProbeErrors Date handling
2 parents 3875093 + a68e780 commit 7db4317

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

LabTech.psm1

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,21 +1744,21 @@ Function Update-LTService{
17441744
}#End End
17451745
}#End Function Update-LTService
17461746

1747-
Function Get-LTError{
1747+
Function Get-LTErrors{
17481748
<#
17491749
.SYNOPSIS
17501750
This will pull the %ltsvcdir%\LTErrors.txt file into an object.
17511751
17521752
.EXAMPLE
1753-
Get-LTError | where {(Get-date $_.Time) -gt (get-date).AddHours(-24)}
1753+
Get-LTErrors | where {(Get-date $_.Time) -gt (get-date).AddHours(-24)}
17541754
Get a list of all errors in the last 24hr
17551755
17561756
.EXAMPLE
1757-
Get-LTError | Out-Gridview
1757+
Get-LTErrors | Out-Gridview
17581758
Open the log file in a sortable searchable window.
17591759
17601760
.NOTES
1761-
Version: 1.2
1761+
Version: 1.3
17621762
Author: Chris Taylor
17631763
Website: labtechconsulting.com
17641764
Creation Date: 3/14/2016
@@ -1770,31 +1770,36 @@ Function Get-LTError{
17701770
Update Date: 3/18/2018
17711771
Purpose/Change: Changed Erroraction from Stop to unspecified to allow caller to set the ErrorAction.
17721772
1773+
Update Date: 1/26/2019
1774+
Purpose/Change: Update for better international date parsing support. Function rename.
1775+
17731776
.LINK
17741777
http://labtechconsulting.com
17751778
#>
17761779
[CmdletBinding()]
17771780
Param()
17781781

17791782
Begin{
1783+
Set-Alias -name LINENUM -value Get-CurrentLineNumber -WhatIf:$False -Confirm:$False
1784+
Write-Debug "Starting $($myInvocation.InvocationName) at line $(LINENUM)"
17801785
$BasePath = $(Get-LTServiceInfo -EA 0 -Verbose:$False -WhatIf:$False -Confirm:$False -Debug:$False|Select-Object -Expand BasePath -EA 0)
17811786
if (!$BasePath){$BasePath = "$env:windir\LTSVC"}
17821787
}#End Begin
17831788

17841789
Process{
17851790
if ($(Test-Path -Path "$BasePath\LTErrors.txt") -eq $False) {
1786-
Write-Error "ERROR: Unable to find log. $($Error[0])"
1791+
Write-Error "ERROR: Line $(LINENUM): Unable to find lelog."
17871792
return
17881793
}
17891794
Try{
17901795
$errors = Get-Content "$BasePath\LTErrors.txt"
1791-
$errors = $errors -join ' ' -split ':::'
1796+
$errors = $errors -join ' ' -split '::: '
17921797
foreach($Line in $Errors){
17931798
$items = $Line -split "`t" -replace ' - ',''
17941799
if ($items[1]){
17951800
$object = New-Object -TypeName PSObject
17961801
$object | Add-Member -MemberType NoteProperty -Name ServiceVersion -Value $items[0]
1797-
$object | Add-Member -MemberType NoteProperty -Name Timestamp -Value $([datetime]$items[1])
1802+
$object | Add-Member -MemberType NoteProperty -Name Timestamp -Value $(Try {[datetime]::Parse($items[1])} Catch {})
17981803
$object | Add-Member -MemberType NoteProperty -Name Message -Value $items[2]
17991804
Write-Output $object
18001805
}
@@ -1803,16 +1808,18 @@ Function Get-LTError{
18031808
}#End Try
18041809

18051810
Catch{
1806-
Write-Error "ERROR: There was an error reading the log. $($Error[0])"
1811+
Write-Error "ERROR: Line $(LINENUM): There was an error reading the log. $($Error[0])"
18071812
}#End Catch
18081813
}#End Process
18091814

18101815
End{
18111816
if ($?){
18121817
}
18131818
Else {$Error[0]}
1819+
Write-Debug "Exiting $($myInvocation.InvocationName) at line $(LINENUM)"
18141820
}#End End
1815-
}#End Function Get-LTError
1821+
}#End Function Get-LTErrors
1822+
Set-Alias -Name Get-LTError -Value Get-LTErrors
18161823

18171824
Function Reset-LTService{
18181825
<#
@@ -2478,7 +2485,7 @@ Function Get-LTProbeErrors{
24782485
Open the log file in a sortable searchable window.
24792486
24802487
.NOTES
2481-
Version: 1.1
2488+
Version: 1.3
24822489
Author: Chris Taylor
24832490
Website: labtechconsulting.com
24842491
Creation Date: 3/14/2016
@@ -2490,39 +2497,50 @@ Function Get-LTProbeErrors{
24902497
Update Date: 3/18/2018
24912498
Purpose/Change: Changed Erroraction from Stop to unspecified to allow caller to set the ErrorAction.
24922499
2500+
Update Date: 1/26/2019
2501+
Purpose/Change: Update for better international date parsing support
2502+
24932503
.LINK
24942504
http://labtechconsulting.com
24952505
#>
24962506
[CmdletBinding()]
24972507
Param()
24982508

24992509
Begin{
2510+
Set-Alias -name LINENUM -value Get-CurrentLineNumber -WhatIf:$False -Confirm:$False
2511+
Write-Debug "Starting $($myInvocation.InvocationName) at line $(LINENUM)"
25002512
$BasePath = $(Get-LTServiceInfo -EA 0 -Verbose:$False -WhatIf:$False -Confirm:$False -Debug:$False|Select-Object -Expand BasePath -EA 0)
25012513
if (!($BasePath)){$BasePath = "$env:windir\LTSVC"}
25022514
}#End Begin
25032515

25042516
Process{
25052517
if ($(Test-Path -Path "$BasePath\LTProbeErrors.txt") -eq $False) {
2506-
Write-Error "ERROR: Unable to find log. $($Error[0])"
2518+
Write-Error "ERROR: Line $(LINENUM): Unable to find log."
25072519
return
25082520
}
25092521
$errors = Get-Content "$BasePath\LTProbeErrors.txt"
2510-
$errors = $errors -join ' ' -split ':::'
2511-
Foreach($Line in $Errors){
2512-
$items = $Line -split "`t" -replace ' - ',''
2513-
$object = New-Object -TypeName PSObject
2514-
$object | Add-Member -MemberType NoteProperty -Name ServiceVersion -Value $items[0]
2515-
$object | Add-Member -MemberType NoteProperty -Name Timestamp -Value $([datetime]$items[1])
2516-
$object | Add-Member -MemberType NoteProperty -Name Message -Value $items[2]
2517-
Write-Output $object
2518-
}#End Foreach
2522+
$errors = $errors -join ' ' -split '::: '
2523+
Try {
2524+
Foreach($Line in $Errors){
2525+
$items = $Line -split "`t" -replace ' - ',''
2526+
$object = New-Object -TypeName PSObject
2527+
$object | Add-Member -MemberType NoteProperty -Name ServiceVersion -Value $items[0]
2528+
$object | Add-Member -MemberType NoteProperty -Name Timestamp -Value $(Try {[datetime]::Parse($items[1])} Catch {})
2529+
$object | Add-Member -MemberType NoteProperty -Name Message -Value $items[2]
2530+
Write-Output $object
2531+
}#End Foreach
2532+
}#End Try
2533+
2534+
Catch{
2535+
Write-Error "ERROR: Line $(LINENUM): There was an error reading the log. $($Error[0])"
2536+
}#End Catch
25192537
}
25202538

25212539
End{
25222540
if ($?){
25232541
}
25242542
Else {$Error[0]}
2525-
2543+
Write-Debug "Exiting $($myInvocation.InvocationName) at line $(LINENUM)"
25262544
}#End End
25272545
}#End Function Get-LTProbeErrors
25282546

@@ -3521,7 +3539,7 @@ Function Initialize-LTServiceModule{
35213539
$PublicFunctions=@(((@"
35223540
ConvertFrom-LTSecurity
35233541
ConvertTo-LTSecurity
3524-
Get-LTError
3542+
Get-LTErrors
35253543
Get-LTLogging
35263544
Get-LTProbeErrors
35273545
Get-LTProxy
@@ -3547,6 +3565,7 @@ Update-LTService
35473565
"@) -replace "[`r`n,\s]+",',') -split ',')
35483566

35493567
$PublicAlias=@(((@"
3568+
Get-LTError
35503569
ReInstall-LTService
35513570
"@) -replace "[`r`n,\s]+",',') -split ',')
35523571

0 commit comments

Comments
 (0)