# Can't use powershell\_out command

**URL:** <https://discourse.chef.io/t/cant-use-powershell-out-command/5721>\
**Category:** Chef Infra (archive)\
**Created:** [September 15, 2014, 7:45pm UTC](https://discourse.chef.io/t/cant-use-powershell-out-command/5721 "2014-09-15T19:45:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avargil\_Raanan](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Avargil\_Raanan](https://discourse.chef.io/u/Avargil_Raanan)\
**Post date:** [September 15, 2014, 7:45pm UTC](https://discourse.chef.io/t/cant-use-powershell-out-command/5721/1 "2014-09-15T19:45:40Z")

</div>

Hello all,

I’m trying to use the powershell\_out command, but get an error while including the Chef::Mixin::PowerShellOut.

This is my recipe:  
Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)  
Chef::Resource.send(:include, Chef::Mixin::PowershellOut)

cmd = powershell\_out!(‘write-host Hello World’);  
Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)  
Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)

# And this is the error I get:

# Recipe Compile Error in c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb

## NameError

uninitialized constant Chef::Mixin::PowershellOut

## Cookbook Trace:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:13:in `from\_file’

## Relevant File Content:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:

6: #  
7: # All rights reserved - Do Not Redistribute  
8: #  
9:  
10:  
11:  
12: Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)  
13\>\> Chef::Resource.send(:include, Chef::Mixin::PowershellOut)  
14:  
15:  
16: cmd = powershell\_out!(‘write-host Hello World’);  
17: Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)  
18: Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)  
19:  
20:  
21:  
22:

Running handlers:  
[2014-09-15T22:35:51+03:00] ERROR: Running exception handlers  
Running handlers complete  
[2014-09-15T22:35:51+03:00] ERROR: Exception handlers complete  
[2014-09-15T22:35:51+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out  
Chef Client failed. 0 resources updated in 8.967519 seconds  
[2014-09-15T22:35:51+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

Please note that there is no error at the first line (Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)), only at the second line.  
I added the first line just for debugging.

I use Chef version 11.12.8.

What do I miss here?

Thanks,  
Raanan.

* * *

Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for  
the sole use of the intended recipient(s). Any review or distribution  
by others is strictly prohibited. If you are not the intended  
recipient, please contact the sender and delete all copies.

---

<div class="post-metadata">

**Author:** ![Kapil\_Shardha1](https://avatars.discourse-cdn.com/v4/letter/k/278dde/32.png) [@Kapil\_Shardha1](https://discourse.chef.io/u/Kapil_Shardha1)\
**Post date:** [September 15, 2014, 7:53pm UTC](https://discourse.chef.io/t/cant-use-powershell-out-command/5721/2 "2014-09-15T19:53:57Z")

</div>

Few months ago I ran into same issue and I was suggested on this forum to have a “library” file with following content:

class Chef  
class Resource  
include Chef::Mixin::PowershellOut  
end  
end

This helped me. Try that and see if it works for you.

Thanks

-Kapil

From: Avargil, Raanan [[mailto:raanan.avargil@intel.com](mailto:raanan.avargil@intel.com)]  
Sent: Monday, September 15, 2014 3:46 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Cc: Avargil, Raanan  
Subject: [chef] Can’t use powershell\_out command

Hello all,

I’m trying to use the powershell\_out command, but get an error while including the Chef::Mixin::PowerShellOut.

This is my recipe:  
Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)  
Chef::Resource.send(:include, Chef::Mixin::PowershellOut)

cmd = powershell\_out!(‘write-host Hello World’);  
Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)  
Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)

# And this is the error I get:

# Recipe Compile Error in c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb

## NameError

uninitialized constant Chef::Mixin::PowershellOut

## Cookbook Trace:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:13:in `from\_file’

## Relevant File Content:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:

6: #  
7: # All rights reserved - Do Not Redistribute  
8: #  
9:  
10:  
11:  
12: Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)  
13\>\> Chef::Resource.send(:include, Chef::Mixin::PowershellOut)  
14:  
15:  
16: cmd = powershell\_out!(‘write-host Hello World’);  
17: Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)  
18: Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)  
19:  
20:  
21:  
22:

Running handlers:  
[2014-09-15T22:35:51+03:00] ERROR: Running exception handlers  
Running handlers complete  
[2014-09-15T22:35:51+03:00] ERROR: Exception handlers complete  
[2014-09-15T22:35:51+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out  
Chef Client failed. 0 resources updated in 8.967519 seconds  
[2014-09-15T22:35:51+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

Please note that there is no error at the first line (Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)), only at the second line.  
I added the first line just for debugging.

I use Chef version 11.12.8.

What do I miss here?

Thanks,  
Raanan.

* * *

Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for  
the sole use of the intended recipient(s). Any review or distribution  
by others is strictly prohibited. If you are not the intended  
recipient, please contact the sender and delete all copies.

---

<div class="post-metadata">

**Author:** ![Avargil\_Raanan](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Avargil\_Raanan](https://discourse.chef.io/u/Avargil_Raanan)\
**Post date:** [September 16, 2014, 4:53am UTC](https://discourse.chef.io/t/cant-use-powershell-out-command/5721/3 "2014-09-16T04:53:18Z")

</div>

Hi Kapil,  
Thank for youe answer!

It didn’t work for me. The source of the error moved to the library instead of the recipe.  
See below:

Compiling Cookbooks…

# ================================================================================ Recipe Compile Error in c:/chef/cache/cookbooks/lan\_driver/libraries/default.rb

## NameError

uninitialized constant Chef::Mixin::PowershellOut

## Cookbook Trace:

c:/chef/cache/cookbooks/lan\_driver/libraries/default.rb:3:in `<class:Resource>' c:/chef/cache/cookbooks/lan_driver/libraries/default.rb:2:in`class:Chef’  
c:/chef/cache/cookbooks/lan\_driver/libraries/default.rb:1:in `\<top (required)\>’

## Relevant File Content:

c:/chef/cache/cookbooks/lan\_driver/libraries/default.rb:

1: class Chef  
2: class Resource  
3\>\> include Chef::Mixin::PowershellOut  
4: end  
5: end  
6:

Running handlers:  
[2014-09-16T07:44:12+03:00] ERROR: Running exception handlers  
Running handlers complete  
[2014-09-16T07:44:12+03:00] ERROR: Exception handlers complete  
[2014-09-16T07:44:12+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out  
Chef Client failed. 0 resources updated in 9.402607 seconds  
[2014-09-16T07:44:12+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

I feel like I miss something very basic.

Raanan

From: Kapil Shardha [[mailto:Kapil.Shardha@SimulationIQ.com](mailto:Kapil.Shardha@SimulationIQ.com)]  
Sent: Monday, September 15, 2014 22:54  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] RE: Can’t use powershell\_out command

Few months ago I ran into same issue and I was suggested on this forum to have a “library” file with following content:

class Chef  
class Resource  
include Chef::Mixin::PowershellOut  
end  
end

This helped me. Try that and see if it works for you.

Thanks

-Kapil

From: Avargil, Raanan [[mailto:raanan.avargil@intel.com](mailto:raanan.avargil@intel.com)]  
Sent: Monday, September 15, 2014 3:46 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)[mailto:chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Cc: Avargil, Raanan  
Subject: [chef] Can’t use powershell\_out command

Hello all,

I’m trying to use the powershell\_out command, but get an error while including the Chef::Mixin::PowerShellOut.

This is my recipe:  
Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)  
Chef::Resource.send(:include, Chef::Mixin::PowershellOut)

cmd = powershell\_out!(‘write-host Hello World’);  
Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)  
Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)

# And this is the error I get:

# Recipe Compile Error in c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb

## NameError

uninitialized constant Chef::Mixin::PowershellOut

## Cookbook Trace:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:13:in `from\_file’

## Relevant File Content:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:

6: #  
7: # All rights reserved - Do Not Redistribute  
8: #  
9:  
10:  
11:  
12: Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)  
13\>\> Chef::Resource.send(:include, Chef::Mixin::PowershellOut)  
14:  
15:  
16: cmd = powershell\_out!(‘write-host Hello World’);  
17: Chef::Log::info(“cmd.stdout = #{cmd.stdout}”)  
18: Chef::Log::info(“cmd.stderr = #{cmd.stderr}”)  
19:  
20:  
21:  
22:

Running handlers:  
[2014-09-15T22:35:51+03:00] ERROR: Running exception handlers  
Running handlers complete  
[2014-09-15T22:35:51+03:00] ERROR: Exception handlers complete  
[2014-09-15T22:35:51+03:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out  
Chef Client failed. 0 resources updated in 8.967519 seconds  
[2014-09-15T22:35:51+03:00] FATAL: NameError: uninitialized constant Chef::Mixin::PowershellOut

Please note that there is no error at the first line (Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)), only at the second line.  
I added the first line just for debugging.

I use Chef version 11.12.8.

What do I miss here?

Thanks,  
Raanan.

* * *

Intel Israel (74) Limited

## This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for  
the sole use of the intended recipient(s). Any review or distribution  
by others is strictly prohibited. If you are not the intended  
recipient, please contact the sender and delete all copies.

---

<div class="post-metadata">

**Author:** ![jdunn](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/jdunn/32/1800_2.png) [@jdunn](https://discourse.chef.io/u/jdunn)\
**Post date:** [September 16, 2014, 5:58am UTC](https://discourse.chef.io/t/cant-use-powershell-out-command/5721/4 "2014-09-16T05:58:05Z")

</div>

On Tue, Sep 16, 2014 at 12:53 AM, Avargil, Raanan  
[raanan.avargil@intel.com](mailto:raanan.avargil@intel.com) wrote:

> Hi Kapil,
> 
> Thank for youe answer!
> 
> It didn’t work for me. The source of the error moved to the library instead  
> of the recipe.
> 
> See below:
> 
> Compiling Cookbooks...
> 
> ================================================================================
> 
> Recipe Compile Error in  
> c:/chef/cache/cookbooks/lan\_driver/libraries/default.rb
> 
> ================================================================================
> 
> NameError
> 
> * * *
> 
> uninitialized constant Chef::Mixin::PowershellOut

Have you declared a dependency on the 'windows' cookbook in your  
metadata for lan\_driver?

- Julian

--  
[Julian C. Dunn [jdunn@aquezada.com](mailto:jdunn@aquezada.com) \* Sorry, I'm ]  
[WWW: [http://www.aquezada.com/staff/julian](http://www.aquezada.com/staff/julian) \* only Web 1.0 ]  
[gopher://sdf.org/1/users/keymaker/ \* compliant!]  
[PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9]

---

<div class="post-metadata">

**Author:** ![Avargil\_Raanan](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Avargil\_Raanan](https://discourse.chef.io/u/Avargil_Raanan)\
**Post date:** [September 16, 2014, 7:54am UTC](https://discourse.chef.io/t/cant-use-powershell-out-command/5721/5 "2014-09-16T07:54:42Z")

</div>

# Hello Julian, Bingo! Indeed I missed the depends "windows" declaration in the metadata.rb file. When I added the dependency, I got the following error:

# Recipe Compile Error in c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb

## NoMethodError

No resource or method named `powershell_out!' for `Chef::Recipe "default"'

## Cookbook Trace:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:15:in `from\_file'

## Relevant File Content:

c:/chef/cache/cookbooks/lan\_driver/recipes/default.rb:

8: #  
9:  
10:  
11:  
12: #Chef::Resource.send(:include, Chef::Mixin::WindowsArchitectureHelper)  
13: Chef::Resource.send(:include, Chef::Mixin::PowershellOut)  
14:  
15\>\> cmd = powershell\_out!('write-host Hello World');  
16: Chef::Log::info("cmd.stdout = #{cmd.stdout}")  
17: Chef::Log::info("cmd.stderr = #{cmd.stderr}")  
18:

But, when I changed the line  
Chef::Resource.send(:include, Chef::Mixin::PowershellOut) to Chef::Recipe.send(:include, Chef::Mixin::PowershellOut) it worked!

Thank you!  
Raanan

-----Original Message-----  
From: Julian C. Dunn [[mailto:jdunn@aquezada.com](mailto:jdunn@aquezada.com)]  
Sent: Tuesday, September 16, 2014 08:58  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] Re: RE: Can't use powershell\_out command

On Tue, Sep 16, 2014 at 12:53 AM, Avargil, Raanan [raanan.avargil@intel.com](mailto:raanan.avargil@intel.com) wrote:

> Hi Kapil,
> 
> Thank for youe answer!
> 
> It didn’t work for me. The source of the error moved to the library  
> instead of the recipe.
> 
> See below:
> 
> Compiling Cookbooks...
> 
> # ======================================================================
> 
> Recipe Compile Error in  
> c:/chef/cache/cookbooks/lan\_driver/libraries/default.rb
> 
> # ======================================================================
> 
> NameError
> 
> * * *
> 
> uninitialized constant Chef::Mixin::PowershellOut

Have you declared a dependency on the 'windows' cookbook in your metadata for lan\_driver?

- Julian

## -- [Julian C. Dunn [jdunn@aquezada.com](mailto:jdunn@aquezada.com) \* Sorry, I'm ] [WWW: [http://www.aquezada.com/staff/julian](http://www.aquezada.com/staff/julian) \* only Web 1.0 ] [gopher://sdf.org/1/users/keymaker/ \* compliant!] [PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9]

Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for  
the sole use of the intended recipient(s). Any review or distribution  
by others is strictly prohibited. If you are not the intended  
recipient, please contact the sender and delete all copies.
