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).
knife node listdoes 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?$nodes = knife node listin my PowerShell console window and everything functioned as I would expect it to,$nodescontained my list of nodes. Same version of chef/chefdk as before. Maybe a windows update fixed the issue?