[英]How do I pass parameters from Child to Parent in Azure RunBooks
So, one would think this would be pretty simple, but I've been dealing with this for a few days now. 因此,有人会认为这很简单,但是我已经处理了几天。
Basically it's like this: 基本上是这样的:
Parent.ps1 Parent.ps1
#calling the childrunbook
./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
$newGreeting = $greeting + 'John Snow'
Write-Output $newGreeting
Child.ps1 Child.ps1
param(
[string]$Firstname,
[string]$Lastname
)
$greeting = 'Hello from the Child Runbook'
Write-Output $greeting
Result 结果
#I was hoping to get
"Hello from the Child Runbook John Snow"
#But all I'm getting is:
"John Snow" :-(
I can do this easily in Powershell, but once I put this same code in Powershell Runbooks on Azure, it's a no go. 我可以在Powershell中轻松地完成此操作,但是一旦将相同的代码放入Azure上的Powershell Runbook中,就不行了。 I thought it might have been a single quote/double quote issue but that hasn't led to any progress.
我以为这可能是单引号/双引号问题,但并没有取得任何进展。 Any ideas?
有任何想法吗?
Thanks in advance! 提前致谢!
When you just run a script like this: 当您像这样运行脚本时:
./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
it executes in it's own scope - meaning that anything written to variables inside the script will only modify a local copy of that variable, and the changes won't touch anything in the parent scope. 它在自己的范围内执行-意味着脚本中写入变量的任何内容都只会修改该变量的本地副本 ,并且更改不会触及父范围内的任何内容。
In order to execute the script in the calling scope , use the dot source operator .
为了在调用范围内执行脚本,请使用点源运算符
.
: :
. ./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
Alternatively you'd just assign the output from the child script to a variable in the calling scope: 另外,您只需将子脚本的输出分配给调用范围内的变量:
$greeting = ./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
$newGreeting = $greeting + 'John Snow'
Write-Output $newGreeting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.