开发者

Executing powershell script file which is a string value

I have script file Get-ProcesWithParam.ps1 as

 param(
 $name
 )

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

}

List-Process -name $name

In another script I get this file name as string variable

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

problem is i need to execute this file (pass the argument to file as well!)

I tried Invo开发者_JAVA百科ke-Command

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

but it did not work, it just prints the file name how can i execute the file which is there in the string variable $stringFile ?


Try &:

$foo = ".\Get-ProcesWithParam.ps1"
$bar="iexplore"
& $foo $bar
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜