从CMD调用Powershell函数

从CMD调用Powershell函数,powershell,cmd,Powershell,Cmd,我有一个脚本,里面有这个函数: function init { Write-Output "test output" } 我想从命令行(不是从PS)调用它,但这些都不起作用: 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

我有一个脚本,里面有这个函数:

function init
{
Write-Output "test output"
}
我想从命令行(不是从PS)调用它,但这些都不起作用:

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>
执行策略不受限制

来自以下方面的提示:

只是一个输入错误:dot sourcing缺少点:
{c:
->
{.c:
谢谢。太傻了!我应该更多地关注被接受的答案,而不是其他答案。这是有效的:
powershell-command.\sc.ps1;init“