It works when adding "Import-Module SQLPS"
Import-Module SQLPS
$SQLServer = "MyServer"
$db = "MyDB"
$inputfile = "e:\mypath\myinputfile.sql"
$outputfile = "e:\mypath\myoutputfile.txt"
Invoke-Sqlcmd -ServerInstance $SQLServer -Database $db -InputFile $inputfile | Out-File -FilePath $outputfile