Powershell_exec result to variable/attirbute

Hi All, I'm fairly new to Chef and I need to get the result of a powershell script into a variable to be used later in the recipe. I've googled this quite a bit and I know this question has been asked before, but nothing I've found allows me to get the result I'm looking for. Here's what I'm attempting to do and not getting any errors, but the 'puts "#{result}" command just writes "#Chef::PowerShell:0x00000000098d3c28" to the console.

powershell_script 'get-newest-tag' do
code <<-EOH
(([Xml] (svn log --xml "http://path_to_svn/" --verbose --username "username" --password 
"password")).Log.LogEntry.Paths.Path | ? { $_.action -eq 'A' -and $_.InnerText -match 
"^/required/path/Site_\d{4}_\d{2}_\d{2}$"} | Select -Property @(@{N='date'; E= 
{$_.ParentNode.ParentNode.Date}},@{N='path'; E={$_.InnerText}}) | Sort Date -Descending | Select 
-First 1).path
EOH

result = powershell_exec(code)
puts "#{result}"
end

As I said, when I run the recipe I get no errors and if I run the code in a Powershell command window I get the expected result which is a path to a tag directory in the repo.

I feel like I must be close but still missing something simple/stupid.

All help and suggestions are appreciated.

We use powershell_out, for example:
count = powershell_out('(Get-ChildItem -path "D:\Program Files\MyApplication\SubFolder\Wait").Count').stdout.to_i

Thanks for the reply craigontour. If I use powershell_out() as you have suggested with .stdout.to_i it does log "0" to the console but I'm hoping for a string response with a path. I've tried to do the same thing with stdout.to_json and stdout.to_str but those both output nothing to the console. Not sure if it's null or an empty string but I'm still in the same position.

As I said before I know the command in "code" does what I expect on the powershell command line, but I'm not sure how to test that it's even doing the same thing from within the recipe.

Sorry, I just gave one of our snippets which converts output to int (.to_i). In your case if the result from execution in PowerShell terminal is a string then just assign output from Powershell_out('..') to a variable and use it in Chef code. In my example, 'count' is a variable used in the recipe further on.

Something like (although you might have to play about with quotes a bit):

#Get path to svn
svn_path = powershell_out('(([Xml] (svn log --xml "http://path_to_svn/" --verbose --username "username" --password "password")).Log.LogEntry.Paths.Path | ? { $.action -eq 'A' -and $.InnerText -match "^/required/path/Site_\d{4}\d{2}\d{2}$"} | Select -Property @(@{N='date'; E=
{$.ParentNode.ParentNode.Date}},@{N='path'; E={$.InnerText}}) | Sort Date -Descending | Select
-First 1).path')

#Path is 'abc'
if svn_path = 'abc'
else
#path is something else
...
etc

Thanks very much for your help so far. I've actually gotten to the point that I'm able to output a response to the console from the powershell_out command but I still have a problem. I made the changes as you suggested and was still not getting the expected output so I started messing with the actual command to see if that was the issue. I started breaking it down into pieces to simplify it and found that if I just run the first part:

(([Xml] (svn log --xml 'http://path_to_repo/' --verbose --username 'username' --password 'password')).Log.LogEntry.Paths.Path)")

I got a response with ALL the paths from that repo, but as soon as I add the next piped part:

| ? { _.action -eq 'A' -and .InnerText -match '^/required/path/Site_\d\d\d\d_\d\d_\d\d'}

I'm back to no output in the console. Is there any chance that the powershell_out command does not like piped commands or am I supposed to be doing something different because it is a piped command?

Thanks again for the help so far!