Write-Output/Error is streamlined
and will send output to the console
This commit is contained in:
@@ -59,17 +59,15 @@ Function Setup-LogFile {
|
|||||||
# Start-Process "cmd.exe" -ArgumentList '/C echo y | some-command'
|
# Start-Process "cmd.exe" -ArgumentList '/C echo y | some-command'
|
||||||
Function Write-Output {
|
Function Write-Output {
|
||||||
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message)
|
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message)
|
||||||
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
Add-Content -Path $Global:LogFile -Value "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") - ${Message}"
|
||||||
$LogEntry = "${Timestamp} - ${Message}"
|
Microsoft.Powershell.Utility\Write-Output $Message
|
||||||
Add-Content -Path $Global:LogFile -Value $LogEntry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Log an error to the log file
|
# Log an error to the log file
|
||||||
Function Write-Error {
|
Function Write-Error {
|
||||||
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message)
|
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message)
|
||||||
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
Add-Content -Path $Global:LogFile -Value "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") - Error: ${Message}"
|
||||||
$LogEntry = "${Timestamp} - Error: ${Message}"
|
Microsoft.Powershell.Utility\Write-Error $Message
|
||||||
Add-Content -Path $Global:LogFile -Value $LogEntry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to determine if the current user context is an Administrator
|
# Function to determine if the current user context is an Administrator
|
||||||
@@ -155,14 +153,6 @@ Function Run-Script {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$LogFileContent = (Get-Content $LogFile)
|
|
||||||
|
|
||||||
# Write the log file output to the console
|
|
||||||
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
|
# Return a Powershell version object from a string
|
||||||
|
|||||||
Reference in New Issue
Block a user