I wrote my own Powershell Log logging function with the stream parameters (in which stream to record the message) and message (message to record).
The idea is that I can write outputs to both the console and the log file. What I do in the function basically determines which thread to post the message to (using the 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, can I check if the -Verbose argument was given?
The goal is to write a message to the log file only if -Verbose has been specified.
I already looked in the following reference documents, but did not find anything useful:
- help about_Parameters
- help about_commonparameters
In addition, the -WhatIf parameter does not work with Write-Verbose.
Thanks so much for your answers!
powershell
dwettstein
source share