Can I have powershell scripts in file with no extension?

Question:

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?

Answer:

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

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 🙂

Source:

Can I have powershell scripts in file with no extension? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply