I have a script with this function inside:
function init
{
Write-Output "test output"
}
I want to call it from the command line (not from PS), but these do not work:
C:\Scripts>powershell -command "& { c:\Scripts\sc.ps1; init }"
init : The term 'init' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:17
+ .\sc.ps1; init
+ ~~~~
+ CategoryInfo : ObjectNotFound: (init:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
C:\Scripts>powershell -file c:\Scripts\sc.ps1 -command init
C:\Scripts>
C:\Scripts>powershell -file .\sc.ps1 -command init
C:\Scripts>
Execution policy is unrestricted.
Hints from: Calling a specific PowerShell function from the command line