I am trying to emulate bash's source command in powershell. The intent is to make any change to my microsoft.powershell_profile.psl and source it into the existing instance of powershell.
The following command works in command-line
$profile_content = [string]::join([environment]::newline,(get-content $profile))
invoke-expression $profile_content
All is good; I put the same into microsoft.powershell_profile.psl and it does not work.
function source{
$profile_content = [string]::join([environment]::newline,(get-content $args[0]))
invoke-expression $profile_content
}
Am I overlooking something?
What you want is already built into PowerShell:
. C:\path\to\some.ps1
See about_Operators:
.Dot sourcing operator
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope.. c:\scripts.sample.ps1
Following should be enough:
function source { . $args }
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