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?

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373

1 Answers1

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

CB.
  • 58,865
  • 9
  • 159
  • 159