# How to pass a varibale to a powershell script?

**URL:** <https://discourse.chef.io/t/how-to-pass-a-varibale-to-a-powershell-script/11442>\
**Category:** Chef Infra (archive)\
**Created:** [September 4, 2017, 12:40pm UTC](https://discourse.chef.io/t/how-to-pass-a-varibale-to-a-powershell-script/11442 "2017-09-04T12:40:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankur760](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@Ankur760](https://discourse.chef.io/u/Ankur760)\
**Post date:** [September 4, 2017, 12:40pm UTC](https://discourse.chef.io/t/how-to-pass-a-varibale-to-a-powershell-script/11442/1 "2017-09-04T12:40:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![joerg.herzinger](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/joerg.herzinger/32/1514_2.png) [@joerg.herzinger](https://discourse.chef.io/u/joerg.herzinger)\
**Post date:** [September 4, 2017, 12:54pm UTC](https://discourse.chef.io/t/how-to-pass-a-varibale-to-a-powershell-script/11442/2 "2017-09-04T12:54:39Z")

</div>

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](https://docs.chef.io)) for exactly this.

---

<div class="post-metadata">

**Author:** ![Ankur760](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@Ankur760](https://discourse.chef.io/u/Ankur760)\
**Post date:** [September 4, 2017, 2:56pm UTC](https://discourse.chef.io/t/how-to-pass-a-varibale-to-a-powershell-script/11442/3 "2017-09-04T14:56:53Z")

</div>

it is giving me following error

invalid multibyte char (UTF-8)  
help please

---

<div class="post-metadata">

**Author:** ![Ankur760](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@Ankur760](https://discourse.chef.io/u/Ankur760)\
**Post date:** [September 4, 2017, 2:59pm UTC](https://discourse.chef.io/t/how-to-pass-a-varibale-to-a-powershell-script/11442/4 "2017-09-04T14:59:27Z")

</div>

kindly help it is giving me following error

invalid multibyte char (UTF-8)

---

<div class="post-metadata">

**Author:** ![cheeseplus](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/cheeseplus/32/960_2.png) [@cheeseplus](https://discourse.chef.io/u/cheeseplus)\
**Post date:** [September 8, 2017, 8:45pm UTC](https://discourse.chef.io/t/how-to-pass-a-varibale-to-a-powershell-script/11442/5 "2017-09-08T20:45:00Z")

</div>

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.
