6

I upgraded to Windows 10 recently and I'm noticing a very strange/annoying issue when running knife commands.

When I run this in the powershell console:

$nodes = knife node list

The value of $nodes is $null and all of my nodes are listed in the console window instead of being captured and stored in the $nodes variable. When I run that same command from Powershell ISE, it functions as expected where the values of $nodes contains my node list.

I've tried several variations, all with the same result...

$nodes = & knife node list
$nodes = Invoke-Expression -Command 'knife node list'
$nodes = $(Invoke-Expression -Command 'knife node list')
$nodes = & knife node list 2>&1
$nodes = & knife node list 3>&1
$nodes = & knife node list 4>&1

What is going on where my powershell console session cannot capture the output from the ruby interpreter but powershell ise session can!?

Name                           Value
----                           -----
PSVersion                      5.0.10586.122
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.122
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Tried with and without the chef powershell module: Import-Module Chef same result.

PS C:\Users\nhudacin> chef -v
Chef Development Kit Version: 0.12.0
chef-client version: 12.8.1
berks version: 4.3.0
kitchen version: 1.6.0

Now here's the kicker... I would just use ISE to get it done, but this command:

$nodes = knife exec -E 'b = Time.now.to_i;a = (b - (336*60*60)).to_i;printf "%-40s %-23s\n", "Name", "Last Check-In";search(:node, "ohai_time:[0 TO #{a}]") { |n| checkIn = Time.at(n["ohai_time"]).strftime("%F %R"); printf "%-40s %-23s\n", n.name, checkIn;}'

works perfectly in powershell console, returning a list of nodes that hasn't checked-in within the last 14 days. When I run it in ISE, it doesn't return a single node (even though I know there are at least 10 that meet this criteria).

4
  • Has anyone come up with a solution for this yet? My knife-fu is seriously hampered by this irritation. Commented Jul 20, 2016 at 9:22
  • No solution yet. The problem seems to come and go. I can again execute the above knife commands in Powershell ISE & Console. No clue what changed. Commented Jul 20, 2016 at 13:28
  • If you run the command without the variable knife node list does it work as expected? Could you also try the following gist and see if the $p.StandardOutput.ReadToEnd() section contains the expected output as well? Commented Aug 4, 2016 at 19:51
  • 1
    I just tried $nodes = knife node list in my PowerShell console window and everything functioned as I would expect it to, $nodes contained my list of nodes. Same version of chef/chefdk as before. Maybe a windows update fixed the issue? Commented Aug 8, 2016 at 14:55

1 Answer 1

1

Try removing the chef module that is installed as part of the ChefDK. That is what fixed this problem for me.

Remove-Module chef

https://github.com/chef/chef/issues/4045

Sign up to request clarification or add additional context in comments.

1 Comment

You are awesome! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.