New Question
0

How to pass parameters to powershell script in userdata?

asked 2015-04-27 22:32:21 +0300

celina-yang gravatar image

My heat template is like:

windows_instance: 
  type: OS::Nova::Server 
  properties: 
  image: {get_param: imagever } 
 flavor: m1.large 
 key_name: test 
 networks: 
   - port: { get_resource: publicport } 
user_data_format: RAW 
user_data: 
  str_replace: 
    template: | 
      #ps1

       testps "$srcurl" "$dest"   -Verbose

   params:
       $dest: { get_param: target_location }
       $srcurl: { get_param: url_src }
       testps: { get_file: test1.ps1 }

test1.ps1 :

param([String]$src, [String]$dest) 
Write-Host "url is:" + $src 
 write-host "dest is:" + $dest

But cloudbase-init.log reported: executeuserdatascript C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\Python27\lib\site-packages\cloudbaseinit\plugins\windows\userdatautils.py:58 2015-04-27 18:40:06.905 1788 DEBUG cloudbaseinit.plugins.windows.userdatautils [-] Userdata stderr: The term 'param' is not recognized as the name of a cmdlet, function, script fi

le, or operable program. Check the spelling of the name, or if a path was inclu

ded, verify that the path is correct and try again.

At C:\Users\cloudbase-init\appdata\local\temp\6ea2afb5-645b-430c-91a2-a67c3201f

5db.ps1:7 char:7

param <<<< ([String]$src, [String]$dest) CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFou

ndException FullyQualifiedErrorId : CommandNotFoundException

So what is the correct way to pass parameter to a powershell script using heat template?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2015-04-28 14:08:53 +0300

ader1990 gravatar image

updated 2015-04-28 14:09:31 +0300

Hello,

You have here some complete examples of Heat templates with PowerShell

https://github.com/openstack/heat-tem...

Hope it helps.

edit flag offensive delete link more

Comments

Thanks a lot. It works now. ANother question: if I need to run several powershell scripts and each of them needs some parameters, what's the correct format to do that? Thanks again

celina-yang gravatar imagecelina-yang ( 2015-04-28 18:34:12 +0300 )edit

I found the sample which can run multiple powershell scripts from the above url. Thx

celina-yang gravatar imagecelina-yang ( 2015-05-01 00:16:59 +0300 )edit

Great! I am glad it worked out.

ader1990 gravatar imageader1990 ( 2015-05-03 21:07:33 +0300 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-04-27 22:32:21 +0300

Seen: 1,443 times

Last updated: Apr 28 '15