执行powershell脚本文件,这是一个字符串值

时间:2011-05-27 07:29:00

标签: powershell

我有脚本文件Get-ProcesWithParam.ps1 as

 param(
 $name
 )

 function List-Process($name)
 {
    Write-Host "Process List"
    get-process -name $name
    #get-process

}

List-Process -name $name

在另一个脚本中,我将此文件名称为字符串变量

$scriptFile = Get-ExecFile # returns "C:\Get-ProcesWithParam.ps1"
#execute the script
# ... other code ...

问题是我需要执行此文件(也将参数传递给文件!)

我尝试了Invoke-Command

 invoke-command -scriptblock { param($name) $scriptFile -name $name } -ArgumentList "chrome"

但它不起作用,它只是打印文件名,我怎么能执行字符串变量$ stringFile中的文件?

1 个答案:

答案 0 :(得分:12)

尝试&

$foo = ".\Get-ProcesWithParam.ps1"
$bar="iexplore"
& $foo $bar
相关问题