# Pass variable from powershell\_script to other resources

**URL:** <https://discourse.chef.io/t/pass-variable-from-powershell-script-to-other-resources/13511>\
**Category:** Chef Infra (archive)\
**Created:** [August 23, 2018, 12:03pm UTC](https://discourse.chef.io/t/pass-variable-from-powershell-script-to-other-resources/13511 "2018-08-23T12:03:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richardp](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@Richardp](https://discourse.chef.io/u/Richardp)\
**Post date:** [August 23, 2018, 12:03pm UTC](https://discourse.chef.io/t/pass-variable-from-powershell-script-to-other-resources/13511/1 "2018-08-23T12:03:16Z")

</div>

Hello,

wonder if anyone can help? I have a cookbook which executes a powershell script to retrieve a password from CyberArk. I then need to use the password in other resources later in the recipe.  
Essentially I want to do this:

powershell\_script 'get\_password' do  
code \<\<-EOH  
do stuff  
return $password  
EOH  
end

excute 'a command' do  
command "somecommand.exe -option1 blah -option2 blah -password $password"  
end

I've been trying to get powershell\_out to work like this:  
script = \<\<-EOH  
do stuff  
return $password  
EOH  
pword = powershell\_out(script)

excute 'a command' do  
command "somecommand.exe -option1 blah -option2 blah -password #{pword}"  
end

But that doesn't work.

I've also tried node.run\_state but I can't get that to work either.

Can anyone help?!

---

<div class="post-metadata">

**Author:** ![stuartpreston](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/stuartpreston/32/1771_2.png) [@stuartpreston](https://discourse.chef.io/u/stuartpreston)\
**Post date:** [August 23, 2018, 3:04pm UTC](https://discourse.chef.io/t/pass-variable-from-powershell-script-to-other-resources/13511/2 "2018-08-23T15:04:15Z")

</div>

Well resources are not designed to pass information between each other, but you can call the internal `powershell_out` mixin directly in your recipe noting that the password to be used would be retrieved at compile time in the Chef run rather than at time of resource execution. i.e. don't expect to retrieve a password that is set in the same Chef run in this way. For a simplified example:

```auto
password = powershell_out!('write-output "password_here!"').stdout.chomp
execute 'your command' do
  command "cmd /c echo #{password}"
end

```

Of course it's less than ideal to be passing around passwords on the command line so remember to add:

```auto
  sensitive true

```

to your execute resource so that any sensitive parameters don't end up in the log.

---

<div class="post-metadata">

**Author:** ![RADITC](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@RADITC](https://discourse.chef.io/u/RADITC)\
**Post date:** [August 23, 2018, 5:40pm UTC](https://discourse.chef.io/t/pass-variable-from-powershell-script-to-other-resources/13511/3 "2018-08-23T17:40:08Z")

</div>

I’d be very interested to see your powershell script for cyber ark!
