Usually powershell script files end with .ps1, and modules end with .psm1.
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?
If yes, Can one have powershell scripts/modules in files with other "texty" extensions like .sh, .ps etc?
Is there an easier way to invoke powershell scripts instead of keying in .\script.ps1 arg1, arg2 , for example like : go arg1, arg2?
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
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.
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 :)
This is what the alias
feature in Powershell is for. You can create your script, ending correctly in .ps1
, and then create an alias so that you can invoke it as build
, start
or whatever.
See the documentation: get-help about_aliases
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With