Functions/Out-Log.ps1
$script:logList = New-Object System.Collections.ArrayList; function Add-Log($message, $section){ $logTimeStamp = Get-Date -Format o; $currentLog = New-Object PSObject; $currentLog | add-member -MemberType NoteProperty -Name "Logged at" -Value $logTimeStamp; $currentLog | add-member -MemberType NoteProperty -Name "Logged by" -Value $loggedInUser; $currentLog | add-member -MemberType NoteProperty -Name "Section" -Value $section; $currentLog | add-member -MemberType NoteProperty -Name "Message" -Value $message; $logList.Add($currentLog) | Out-Null; } function Out-Log { $logList | Format-List * | Out-File -FilePath "$ScannedDataPath\log_$scriptTimeStamp.txt"; } function Out-Error($errorMessageRaw){ $errorTimeStamp = Get-Date -Format o; $errorMessage = "[$errorTimeStamp] - $errorMessageRaw" $errorMessage | Out-File -FilePath $ErrorLogPath -NoClobber -Append; } function Out-ErrorList { $Global:Error | Format-List * | Out-File -FilePath $ErrorLogPath -NoClobber -Append; $Global:Error.Clear(); } |