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
精彩评论