我可以在没有扩展名的文件中使用 powershell 脚本吗? [英] Can I have powershell scripts in file with no extension?

查看:36
本文介绍了我可以在没有扩展名的文件中使用 powershell 脚本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Usually powershell script files end with .ps1, and modules end with .psm1.

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

Can one have powershell scripts/modules in files with no extension? Just "build" or "start" and so on? Will this cause an issue in any specific environment?

如果是,是否可以在具有其他文本"扩展名(如 .sh、.ps 等)的文件中包含 powershell 脚本/模块?

If yes, Can one have powershell scripts/modules in files with other "texty" extensions like .sh, .ps etc?

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

Is there an easier way to invoke powershell scripts instead of keying in .\script.ps1 arg1, arg2 , for example like : go arg1, arg2?

推荐答案

不,你不能.Import-Module 的错误信息非常清楚:

No, you can't. The error message for Import-Module is pretty clear:

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

如果您尝试调用带有非标准扩展名的脚本,Windows 将简单地弹出您想用什么程序打开它?"对话.如果您选择使用 Powershell 打开,则会生成一个新的 Powershell 进程,该进程将执行相同的操作.

And if you try to call a script with a non-standard extension, Windows will simply pop the "What program would you like to open this with?" dialog. If you choose to open with Powershell, a new Powershell process will be spawned, which will just do the same thing.

如果你尝试分配一个新的扩展名,比如 .xyz 总是用 Powershell 打开,你最终会产生一系列永无止境的 Powershell 进程,每个进程都徒劳无功使用 Powershell 的新实例打开文件.我刚试过:)

If you try to assign a new extension, like .xyz to always be opened with Powershell, you will end up with an never-ending series of Powershell processes being spawned, each attempting in vain to open the file with a new instance of Powershell. I just tried it :)

这篇关于我可以在没有扩展名的文件中使用 powershell 脚本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆