如何给PowerShell远程函数传递参数


PowerShell交流中心分类: 变量-函数-脚本-条件-循环-参数如何给PowerShell远程函数传递参数
0
MissIsabel asked 7年 ago

现在有这么一段脚本

param($serverlist,$Name) 
$func{
function Say-Hello
{
param($Name)
Write-Host "$Name,您好!"
}

Say-Hello -Name 'PSTips.NET'
}

$server = get-content "$serverlist"
Invoke-Command -ComputerName $server -ScriptBlock $func

 

怎么能让定义好的 $name 这个变量被 func里面的脚本使用?

1 Answers
0
Best Answer
Mooser Lee 管理员 answered 7年 ago
Invoke-Command -ComputerName $server -ScriptBlock $func -ArgumentList $Name