Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have powershell scripts in file with no extension?

Tags:

powershell

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?

like image 335
Zasz Avatar asked Feb 20 '23 07:02

Zasz


2 Answers

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 :)

like image 56
latkin Avatar answered Mar 05 '23 09:03

latkin


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

like image 37
Dominic Cronin Avatar answered Mar 05 '23 07:03

Dominic Cronin