2

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.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Peter Core
  • 193
  • 1
  • 2
  • 16

1 Answers1

3

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.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • You should take care where you put the sourced file, probably at the end so it will not be overwritten. – Timo Oct 24 '20 at 09:15
  • 1
    @Timo: True.. But if your source file is having functions then you need to put it somewhere before calling the function. – Ranadip Dutta Oct 28 '20 at 10:03