执行PowerShell脚本文件,它是一个字符串值
问题描述:
我有脚本文件获取-ProcesWithParam.ps1作为执行PowerShell脚本文件,它是一个字符串值
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 -scriptblock { param($name) $scriptFile -name $name } -ArgumentList "chrome"
但它没有工作,它只是打印文件名我怎么能执行文件,那里的字符串变量$ stringFile?
答
尝试&
:
$foo = ".\Get-ProcesWithParam.ps1"
$bar="iexplore"
& $foo $bar
哇......我试过很多其他的事情,但是这个作品:)! – JeeZ 2011-05-27 08:22:26