Powershell_script

Hello,

I would like to add some logging into my powershell_script section of my recipe. write-host doesn’t work, what is the best method for writing information to the chef log file?

Pipe to Out-file ?

Because you are in a powershell session, you dont have access to amy of the recipie DSL methods. While using out-file or another powershll accesible file writing technique to write to the chef log may work, that is also wrought with file locking danger. Some other possibilities include:

  • writing to another file.
  • serializing whatever state you are trying to log to a separate json file and then have a ruby block get notified by your powershell_script and have it consume the json and use chef recipie DSL logging methods to properly log them to the chef log.

You could also use powershell_out in a custom resource if you need to get the output from the command to do something with.