File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ function Get-DNSDebugLog
7171 {
7272 Write-Debug " PROCESS: Starting to processing File: $DNSLog "
7373
74- getDNSLogLines - DNSLog $DNSLog | % {
74+ getDNSLogLines - DNSLog $DNSLog | ForEach-Object {
7575
7676 # Overall Total
7777 $nTotalEvaluated = $nTotalEvaluated + 1
@@ -129,6 +129,6 @@ function getDNSLogLines
129129 }
130130 elseif ($PathCorrect -eq $true )
131131 {
132- Get-Content $DNSLog | % { $_ }
132+ Get-Content $DNSLog | ForEach-Object { $_ }
133133 }
134134}
Original file line number Diff line number Diff line change 11# Demo code to illustrate using the lib/Write-Log.ps1 logging module
2- # Based on code by Martin Norlunn:
2+ # Based on code by Martin Norlunn:
33# https://www.norlunn.net/2020/06/07/powershell-write-log-function/
4- #
4+ #
55# To run:
66# & '.\Write-Log-Demo.ps1 -Verbose'
77
88[CmdletBinding ()]
99param ()
1010# Cmdletbinding is required to run script with -Verbose
11-
11+
1212# Import the log function, or declare it directly here
1313. " .\lib\Write-Log.ps1"
14-
14+
1515# Write an informational message
1616Write-Log - Message " Script invoked as user: $env: USERNAME "
17-
17+
1818# Write a warning
1919Write-Log - Warning " This is a warning"
20-
20+
2121# Handle errors
2222try
2323{
Original file line number Diff line number Diff line change @@ -9,21 +9,21 @@ function Write-Log
99 [String ]$LogFolderPath = " $PSScriptRoot \Logs" ,
1010 [String ]$LogFilePrefix = ' Log'
1111 )
12-
12+
1313 $Date = Get-Date - Format " dd_MMMM_yyyy"
1414 $Time = Get-Date - Format " HH:mm:ss.f"
1515 $LogFile = " $LogFolderPath \$LogFilePrefix `_$Date .log"
16-
16+
1717 if (-not (Test-Path - Path $LogFolderPath ))
1818 {
1919 [Void ](New-Item - ItemType Directory - Path $LogFolderPath - Force)
2020 }
21-
21+
2222 if (-not (Test-Path - Path $LogFile ))
2323 {
2424 [Void ](New-Item - ItemType File - Path $LogFile - Force)
2525 }
26-
26+
2727 $LogMessage = " [$Time ] "
2828
2929 if ($PSBoundParameters.ContainsKey (" ErrorObj" ))
@@ -41,6 +41,6 @@ function Write-Log
4141 $LogMessage += " Info: $Message "
4242 Write-Verbose - Message $LogMessage
4343 }
44-
44+
4545 Add-Content - Path $LogFile - Value " $LogMessage "
4646}
You can’t perform that action at this time.
0 commit comments