# Powershell\_script

**URL:** <https://discourse.chef.io/t/powershell-script/8822>\
**Category:** Chef Infra (archive)\
**Created:** [June 30, 2016, 7:03am UTC](https://discourse.chef.io/t/powershell-script/8822 "2016-06-30T07:03:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peterthompson](https://avatars.discourse-cdn.com/v4/letter/p/e36b37/32.png) [@peterthompson](https://discourse.chef.io/u/peterthompson)\
**Post date:** [June 30, 2016, 7:03am UTC](https://discourse.chef.io/t/powershell-script/8822/1 "2016-06-30T07:03:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![smuckers](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@smuckers](https://discourse.chef.io/u/smuckers)\
**Post date:** [June 30, 2016, 9:41pm UTC](https://discourse.chef.io/t/powershell-script/8822/2 "2016-06-30T21:41:35Z")

</div>

Pipe to Out-file ?

---

<div class="post-metadata">

**Author:** ![Matt\_Wrock](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/matt_wrock/32/3394_2.png) [@Matt\_Wrock](https://discourse.chef.io/u/Matt_Wrock)\
**Post date:** [July 1, 2016, 12:13am UTC](https://discourse.chef.io/t/powershell-script/8822/3 "2016-07-01T00:13:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Steven\_Murawski](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/steven_murawski/32/1450_2.png) [@Steven\_Murawski](https://discourse.chef.io/u/Steven_Murawski)\
**Post date:** [July 7, 2016, 10:03pm UTC](https://discourse.chef.io/t/powershell-script/8822/4 "2016-07-07T22:03:18Z")

</div>

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