我可以在文件中包含无扩展名的Powershell脚本吗?

Zas*_*asz 4 powershell

通常,powershell脚本文件以.ps1结尾,模块以.psm1结尾。

可以在没有扩展名的文件中包含Powershell脚本/模块吗?只是“构建”或“开始”等等?这会在任何特定环境中引起问题吗?

如果是,可以在文件中带有其他“ texty”扩展名(例如.sh,.ps等)的Powershell脚本/模块吗?


有没有更简单的方法来调用powershell脚本,而不是键入。\ script.ps1 arg1,arg2,例如:go arg1,arg2?

lat*_*kin 5

不,你不能。错误消息Import-Module非常清楚:

Import-Module : The extension '.xyz' is not a valid module extension. The supported module extensions are '.dll',
'.ps1', '.psm1', '.psd1', '.cdxml' and '.xaml'. Correct the extension then try adding the file
Run Code Online (Sandbox Code Playgroud)

而且,如果您尝试使用非标准扩展名调用脚本,则Windows只会弹出“您要使用哪个程序打开它?” 对话。如果选择使用Powershell打开,则将产生一个新的Powershell进程,该进程将执行相同的操作。

如果您尝试分配一个新的扩展名(例如.xyz始终与Powershell一起打开),那么最终将产生一系列永无休止的Powershell进程,每个进程都徒劳地尝试使用Powershell的新实例打开文件。我只是试过了:)