I have a function called Write-Logs being called in the many of other scripts/foreach loops. and I realize that when it comes to looping it’s taking a lot of time. I suppose it’s due to I/O overhead. I can’t/am not allowed to update to any of the main scripts due to certain reasons. is there something that can be done at the function level to improve the performance. I’m open to any suggestions.
Function Write-Logs {
Param(
[parameter(Mandatory=$true)][string]$logContent,
[parameter(Mandatory=$true)][string]$logPath
)
$currentTime = Get-Date
If(!(Test-Path $logPath)){
New-Item -Path $logPath -ItemType 'file' -Force
}
Write-Output "$($currentTime): $($logContent)" | Out-File $logPath -Append
}
New contributor
0xNewbie Lam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.