PowerShell script search point does not end with .ps1

From PowerShell, I can “calculate the source” of another PowerShell program. I can execute it as if it were written inside the first. Example:

Write-Host 'before'
. MyOtherProgram.ps1
Write-Host 'after'

MyOtherProgram is 'included' inside the main program, just as if its contents were copied / pasted.

The problem is that I can only specify the source with a file name ending with .ps1
I cannot with MyOtherProgram.liborMyOtherProgram.whatever

Does anyone have a way to calculate a PowerShell script source that doesn't end in .ps1?

+3
source share
2 answers

Another way Invoke-Expression:

$code = Get-Content ./MyOtherProgram.lib | Out-String
Invoke-Expression $code
+6
source

, PowerShell, , - script , .

Rename-Item C:\Path\MyScript.whatever C:\Path\MyScript.ps1
. C:\Path\MyScript.ps1
Rename-Item C:\Path\MyScript.ps1 C:\Path\MyScript.whatever
+1

All Articles