# Chef PowerShell write-host

**URL:** <https://discourse.chef.io/t/chef-powershell-write-host/6639>\
**Category:** Chef Infra (archive)\
**Created:** [May 8, 2015, 8:37am UTC](https://discourse.chef.io/t/chef-powershell-write-host/6639 "2015-05-08T08:37:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Hawkins](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@Simon\_Hawkins](https://discourse.chef.io/u/Simon_Hawkins)\
**Post date:** [May 8, 2015, 8:37am UTC](https://discourse.chef.io/t/chef-powershell-write-host/6639/1 "2015-05-08T08:37:05Z")

</div>

All,

I have a bunch of write-host statements in a powershell block in a recipe.

When I run the script using powershell on the local machine, the write-host output writes the messages to the console.

When I run it via the chef-run it doesn’t:

[2015-05-08T09:30:48+01:00] INFO: powershell\_script[rename\_hostname] ran successfully

```
- execute "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -InputFormat None -File

```

“C:/Users/ADMINI~1/AppData/Local/Temp/1/chef-script20150508-2840-aitigl.ps1”  
[2015-05-08T09:30:48+01:00] INFO: Chef Run complete in 57.125115 seconds

How do I get the chef-run to write the write-host commands to the console on the run?

Cheers,  
Simon.

* * *

Disclaimer

This message is intended only for the use of the person(s) (“Intended Recipient”) to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.

Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

* * *

---

<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:** [May 14, 2015, 5:41pm UTC](https://discourse.chef.io/t/chef-powershell-write-host/6639/2 "2015-05-14T17:41:10Z")

</div>

The simple answer is, “you don’t”. What’s the purpose or intention? Do you want additional logging? If so, that’s where the log resource comes into play and may suggest areas where you are doing to many steps in one powershell resource or may be a good place to build a lightweight resource provider (LWRP).

Steve

Steven Murawski  
Community Software Development Engineer @ Chef  
Microsoft MVP - PowerShell  
[http://stevenmurawski.com](http://stevenmurawski.com) [[http://stevenmurawski.com/](http://stevenmurawski.com/)]  
On 5/8/2015 3:37:26 AM, Simon Hawkins [simon.hawkins@totaljobsgroup.com](mailto:simon.hawkins@totaljobsgroup.com) wrote:  
All,

I have a bunch of write-host statements in a powershell block in a recipe.

When I run the script using powershell on the local machine, the write-host output writes the messages to the console.

When I run it via the chef-run it doesn’t:

[2015-05-08T09:30:48+01:00] INFO: powershell\_script[rename\_hostname] ran successfully

```
- execute "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -InputFormat None -File

```

“C:/Users/ADMINI~1/AppData/Local/Temp/1/chef-script20150508-2840-aitigl.ps1”  
[2015-05-08T09:30:48+01:00] INFO: Chef Run complete in 57.125115 seconds

How do I get the chef-run to write the write-host commands to the console on the run?

Cheers,  
Simon.  
Disclaimer  
This message is intended only for the use of the person(s) (“Intended Recipient”) to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any dissemination, distribution, copying or other use of this message or any of its content by any person other than the Intended Recipient may constitute a breach of civil or criminal law and is strictly prohibited. If you are not the Intended Recipient, please contact the sender as soon as possible.  
Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

---

<div class="post-metadata">

**Author:** ![Yoshi\_Spendiff](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/yoshi_spendiff/32/13_2.png) [@Yoshi\_Spendiff](https://discourse.chef.io/u/Yoshi_Spendiff)\
**Post date:** [May 14, 2015, 5:45pm UTC](https://discourse.chef.io/t/chef-powershell-write-host/6639/3 "2015-05-14T17:45:17Z")

</div>

Try using the -l debug flag to your chef runs. You'll have to sift through  
a lot of junk but the output should be there.

Use it for debugging but don't rely on the output from the script for your  
recipes to work or as a regular thing for you to read.

You can use Chef::Log. in your recipes for output in a Chef run.

On Thu, May 14, 2015 at 10:41 AM, Steven Murawski \<[steven.murawski@gmail.com](mailto:steven.murawski@gmail.com)

> wrote:

> The simple answer is, "you don't". What's the purpose or intention? Do  
> you want additional logging? If so, that's where the log resource comes  
> into play and may suggest areas where you are doing to many steps in one  
> powershell resource or may be a good place to build a lightweight resource  
> provider (LWRP).
> 
> Steve
> 
> Steven Murawski  
> Community Software Development Engineer @ Chef  
> Microsoft MVP - PowerShell  
> [http://stevenmurawski.com](http://stevenmurawski.com)
> 
> On 5/8/2015 3:37:26 AM, Simon Hawkins [simon.hawkins@totaljobsgroup.com](mailto:simon.hawkins@totaljobsgroup.com)  
> wrote:
> 
> All,
> 
> I have a bunch of write-host statements in a powershell block in a recipe.
> 
> When I run the script using powershell on the local machine, the  
> write-host output writes the messages to the console.
> 
> When I run it via the chef-run it doesn’t:
> 
> [2015-05-08T09:30:48+01:00] INFO: powershell\_script[rename\_hostname] ran  
> successfully
> 
> ```
> - execute "powershell.exe" -NoLogo -NonInteractive -NoProfile
> 
> ```
> 
> -ExecutionPolicy Unrestricted -InputFormat None -File
> 
> "C:/Users/ADMINI~1/AppData/Local/Temp/1/chef-script20150508-2840-aitigl.ps1"
> 
> [2015-05-08T09:30:48+01:00] INFO: Chef Run complete in 57.125115 seconds
> 
> How do I get the chef-run to write the write-host commands to the console  
> on the run?
> 
> Cheers,
> 
> ## Simon.
> 
> _Disclaimer_
> 
> This message is intended only for the use of the person(s) ("Intended  
> Recipient") to whom it is addressed. It may contain information which is  
> privileged and confidential. Accordingly any dissemination, distribution,  
> copying or other use of this message or any of its content by any person  
> other than the Intended Recipient may constitute a breach of civil or  
> criminal law and is strictly prohibited. If you are not the Intended  
> Recipient, please contact the sender as soon as possible.
> 
> ## Totaljobs Group Limited Registered Office: Bluefin Building, 110 Southwark Street, London, SE1 0TA, UK Registered in England and Wales under company no. 4269861

--  
Yoshi Spendiff  
Ops Engineer  
Indochino  
Mobile: +1 778 952 2025  
Email: [yoshi.spendiff@indochino.com](mailto:yoshi.spendiff@indochino.com)
