Can any one tell passing variable to sql script to replace value in it through powershell_script resource?

here path and nam1 are assigned variable. KIndly also tell me to changes to be made in sql file ???

$database = “aaaa”

powershell_script ‘script_name’ do
code <<-EOH
Invoke-sqlcmd -ServerInstance “#{nam1}” -InputFile “#{path}” -variable $database

@Ankur760 The Chef construct you are looking for here is a template. The template resource can be used to combine variables and a template file.

Templates are covered in the Learn the Basics module on our Learn Chef site: and you can find more information here:

thanks alot for your help…
Wish same in future

[quote=“Ankur760, post:3, topic:11462, full:true”]
thanks alot for your help…

thanks alot for your help…
Wish same in future

can you code one simple 2 line template for passing variables to sql file ?

In your attribute file:

default['my_cookbook']['file']['variable'] = 'dynamic variable'

In your recipe:

template '~/target/location/of/generated/file.log' do
  source 'template_file.log.erb'
    var1: 'static variable',
    var2: node['my_cookbook']['file']['variable']

in the template_file.log.erb you can refere to the passed variables with the following syntax:

This is the var1 is variable content:<%= @var1 %>
This is the var2 is variable content:<%= @var2 %>

The template_file.log.erb should be creted within your cookbook under ./templates/default

For further information check