How to pass a varibale to a powershell script?

i want to pass a variable $instance = #{node[‘t1’][‘message’]}.
i want it to pass through code property of powershell_script resource

can i do like this ???

powershell_script ‘run remote script’ do
code '. C:\t1\files\default\shell_cmd.ps1 “$instance”'
end
please help soon

As on pretty much all systems, single quotes do not allow string interpolation, so you need to use double quotes for your code string and escape the other double quotes.

powershell_script ‘run remote script’ do
  code ". C:\t1\files\default\shell_cmd.ps1 \"#{node['t1']['message']}\""
end

P.S.: Please use the means given to you by the system to format code blocks and the likes. This makes “helping you soon” a lot easier.
Also, there are lots of examples in the chef docs (https://docs.chef.io) for exactly this.

it is giving me following error

invalid multibyte char (UTF-8)
help please

kindly help it is giving me following error

invalid multibyte char (UTF-8)

Ankur,

This error is likely because you have non-UTF8 characters your cookbook files. You need to ensure that all files have their encoding set to UTF-8 which is typically a setting in your text editor of choice. On Windows we are fans of both Visual Studio Code and/or Atom which are both free editors.

If you require “help soon” the best place to ask is in the Community Slack but responses to questions on the mailing list and slack are entirely volunteer based. If you or your business needs a higher level of support that is available as a customer.