Edit Verbose Output of cmdlets
I wanted to append information to the verbose output of a cmdlet so that logging is neater. Well, it seems there is no nice way to do that?
This is what I came up with, redirecting the verbose stream, manipulating the verbose string, and then write it verbose back out
$verbose_info = get-aduser awittig | set-aduser -Replace @{comment = 'test'} -Verbose 4>&1 write-verbose "$(get-date) - $($verbose_info -split ':')" -Verbose #Output VERBOSE: 04/2/2018 16:35:01 - Performing the operation "Set" on target "CN=Wittig\, Alexander,OU=users,OU=test,DC=AD,DC=bloodyshell,DC=com".