0

I have written the following code

$sb = {
    . .\Myfunctions.ps1
    $x = MyFunction1
    $y = MyFunction2
    $x + $y
}

$cred = Get-Credential "domain\user"

Invoke-Command -Computer localhost -Credentials $cred -ScriptBlock $sb

This does not work because it says The term .\MyFunctions.ps1 is not recognized as commandlet

Why can't I include a file inside a script block?

1 Answer 1

1

The problem is that the $pwd (current directory) in the script block is different from the actual console path casued this because you are using invoke-command with -computer parameter is like you are do it in a remoting session. Try to put full path to your script to call it or just use ( if locally) & $sb

Sign up to request clarification or add additional context in comments.

Comments

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.