I have written my own Powershell logging function Log
with parameters stream
(on which stream to write the message) and message
(the message to write).
The idea is that i can write the outputs both to the console and to a log-file. What I do in the function is basically determine on which stream to publish the message (with a switch statement) and then write the message to the stream and the log-file:
switch ($stream) {
Verbose {
Write-Output "$logDate [VERBOSE] $message" | Out-File -FilePath $sgLogFileName -Append
Write-Verbose $message
break
}
}
The question is now, is it possible to check if the -Verbose argument was given?
The goal is to write the message to the log-file only if the -Verbose was given.
I looked already in the following help docs but didn't find anything helpful:
- help about_Parameters
- help about_commonparameters
Also, the -WhatIf parameter does not work with Write-Verbose.
Thanks a lot for your answers!