10

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 Invoke-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 ?

1 Answer 1

14

Try &:

$foo = ".\Get-ProcesWithParam.ps1"
$bar="iexplore"
& $foo $bar
Sign up to request clarification or add additional context in comments.

1 Comment

In the case of using a switch as a param, I got it working by running & $foo -myswitch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.