From 64e4ca1237506ed48aa6472bc87a4c90be34b682 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Sat, 23 Oct 2021 13:54:04 -0400 Subject: [PATCH] delete log file after Run-Script if it's empty --- Tools.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Tools.ps1 b/Tools.ps1 index 401c446..3ad93d3 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -149,9 +149,14 @@ Function Run-Script { } } } + + $LogFileContent = (Get-Content $LogFile) + ## Write the log file output to the console - If ( Test-Path $LogFile ) { Get-Content -Path $LogFile | Write-Output } - Else { Write-Output "Log file not found at ""$LogFile""" } + If ( $LogFileContent ) { Write-Output $LogFileContent } + + ## Delete the log file if it's empty + Else { Remove-Item $LogFile -Force } } ## Return a Powershell version object from a string