Log writing PowerShell function
I don't see anything wrong or debatable in this so far. Just a couple nitpicks:

I would use parameter splatting to make the color part more compact. For example, from my own log function:
  switch ($Severity) {
      Debug    { $colors = @{ForegroundColor=&quot;DarkGray&quot;                               } }
      Info     { $colors = @{                                                         } }
      Warning  { $colors = @{ForegroundColor=&quot;Black&quot;      ; BackgroundColor=&quot;Yellow&quot;  } }
      Error    { $colors = @{ForegroundColor=&quot;White&quot;      ; BackgroundColor=&quot;DarkRed&quot; } }
      Critical { $colors = @{ForegroundColor=&quot;DarkYellow&quot; ; BackgroundColor=&quot;DarkRed&quot; } }
  }

  Write-Host @colors &quot;$($Severity): $Message&quot;



Maybe you could go even further with a hash of hashs and do Write-Host @colors[&quot;error&quot;] or something like that.

To create a file only if the file doesn't already exist, you can call New-Item directly, it will throw an exception if the file already exists which you can just ignore with a try-catch or with -ErrorAction SilentlyContinue, saving a couple lines.

Why not make all the configuration fetched from the config file optional parameters, with the values in the file as default values ? That would help if you ever have to use the function on the fly, in a shell or as a debug tool.

Very personal opinion, but I would personally put the default value of $OperationResult to Info, as this is the most common case for me and I'd appreciate just whipping out a simple Write-Log &quot;mymessage&quot; without extra typing.

Last one, this one depends on your environment, but Write-Log is also a function in the officiel VMWare vSphere module that is quite widely used. I wouldn't change any code because of that but remember to document that if you ever have to distribute your code.


Overall I think your cmdlet is pretty readable and produces a log that is easy enough to parse, so it ticks all the important boxes for me.