Powershell 如何在Azure Runbook中将参数从子级传递到父级

Powershell 如何在Azure Runbook中将参数从子级传递到父级,powershell,azure,azure-automation,runbook,Powershell,Azure,Azure Automation,Runbook,所以,有人会认为这很简单,但我已经处理了几天了 基本上是这样的: ./childrunbook.ps1 -FirstName 'John'-LastName 'Snow' Parent.ps1 #calling the childrunbook ./childrunbook.ps1 -FirstName 'John'-LastName 'Snow' $newGreeting = $greeting + 'John Snow' Write-Output $newGreeting Chi

所以,有人会认为这很简单,但我已经处理了几天了

基本上是这样的:

./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
Parent.ps1

  #calling the childrunbook
./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
 $newGreeting = $greeting + 'John Snow'
 Write-Output $newGreeting
Child.ps1

param(
   [string]$Firstname, 
   [string]$Lastname
)

$greeting = 'Hello from the Child Runbook'
Write-Output $greeting
结果

#I was hoping to get 
"Hello from the Child Runbook John Snow"
#But all I'm getting is:
"John Snow"  :-( 
我可以在Powershell中轻松做到这一点,但一旦我在Azure上的Powershell运行手册中添加了相同的代码,就不可能了。我认为这可能是一个单引号/双引号的问题,但这并没有带来任何进展。有什么想法吗


提前谢谢

当您运行这样的脚本时:

./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
它在自己的作用域中执行——这意味着脚本中写入变量的任何内容都只会修改该变量的本地副本,而更改不会涉及父作用域中的任何内容

要在调用范围内执行脚本,请使用点源运算符:

或者,您只需将子脚本的输出分配给调用范围中的变量:

$greeting = ./childrunbook.ps1 -FirstName 'John'-LastName 'Snow'
$newGreeting = $greeting + 'John Snow'
Write-Output $newGreeting

谢谢你@Mathias R.Jessen我欠你一杯啤酒!