[chef] RE: Get return value from powershell into attribute


Chronological Thread 
  • From: Adam Edwards < >
  • To:
  • Subject: [chef] RE: Get return value from powershell into attribute
  • Date: Sun, 10 Aug 2014 08:10:16 -0700

Hey, no monkeypatching PowershellScript. J

 

Can you try this without powershell_out and see if you can get the same failure? I had no issues with the following fragment run via chef-apply – I just piped the output to a file in my recipe and after running chef-apply I verified the contents of the output file:

 

powershell_script 'filever' do

  code <<-EOH

   [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\\Program Files\\Internet Explorer\\iexplore.exe").FileVersion > ~\\fileversion.txt

EOH

End

 

Chef-apply returned successfully when running a file with those contents and produced the following results:

 

  11.00.9600.16384 (winblue_rtm.130821-1623)

 

Thanks Iain, I’m definitely curious as to what’s causing this and if there’s something we can do to prevent it.

 

-Adam

From: Iain Prior [mailto: "> ]
Sent: Sunday, August 10, 2014 12:14 AM
To: ">
Subject: [chef] Get return value from powershell into attribute

 

Hi guys

 

I have been bashing my head against this for hours, and I’m sure there is something simple and obvious that I just don’t know..

 

I want to run a powershell script to get the FileVersion attribute of a file and save that into a chef attribute on the server.

 

Here is the recipe I’m struggling with. Please help?

 

::Chef::Resource::PowershellScript.send(:include, Chef::Mixin::PowershellOut)

 

powershell_script "read-version" do

  cwd Chef::Config[:file_cache_path]

  code <<-EOH

    sleep 5

    [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\\Program Files\\xxx\\yyy\\zzz.dll").FileVersion | fl

   Return

  EOH

  node.default[:gac_integration][:version] = powershell_out(code).stdout

  node.default[:gac_integration][:version] = powershell_out(code).stderr

end

 

Here is the error I am getting..

 

At line:1 char:58 + [System.Diagnostics.FileVersionInfo]::GetVersionInfo(C:\Program Files\Gulf A ... + ~ Missing ')' in method call. At line:1 char:58 + [System.Diagnostics.FileVersionInfo]::GetVersionInfo(C:\Program Files\Gulf A ... + ~~~~~~~~~~ Unexpected token 'C:\Program' in _expression_ or statement. At line:1 char:130 + ... Integration.dll).FileVersion | fl + ~ Unexpected token ')' in _expression_ or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall

 

 

Many regards

Iain

 




Archive powered by MHonArc 2.6.16.

§