Search code examples
powershelldot-source

Permanently dot Source a File?


I am using a Custom-Powershell-Script all the time. I simply can Dot-Source the File, but I have to do this in every session.

. .\Hello-World.ps1

Is there a way to dot-source a file permanently? I don't want to do this over and over again.


Solution

  • Check first your profiler is present or not.

    Test-Path $profile
    

    If it is returning False, we have to create them. Run PS in elevated mode.

    New-Item -path $profile -type file –force 
    

    So it will ask the confirmation.

    Open the file named Microsoft.Powershell_profile.ps1 from the path and add the entry there directly like:

    . .\Hello-World.ps1
    

    Once done,Save and restart it. If you open it again, you should be able to see the Dot Source Functions present in the Hello-World.ps1

    By default $profile path should be:

    C:\Users\Username\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

    Hope it helps.