Using Dot Sourcing is a quick and easy way of getting functions or data into your Powershell console or script.
If you run a Powershell script from a console, all the data in memory is deleted when the script ends (unlike the ISE where it is still in memory).
This is because the script is running in a different session (memory space) so is separate from the Powershell console that runs the script.
This quick script will demonstrate this.
$one = 1
$two = 2
$three = 3
$bob = $one + $three
$jase
If I run this script in the ISE I will get (surprisingly enough) no output.
but I am able to see the variables $one, $two, $three and $bob
Now if I try the same thing in a standard Powershell window I get.
The variables in the script test.ps1 are not accessible in the console once the script has finished executing. Effectively the test.ps1 script is running in a separate part of memory (or a session) that is cleared down when exiting.
So now we Dot Source the script.
By adding a full stop in front of the script we instruct Powershell to run in the current session. This makes all the variables available after execution.
It also works the other way in that any data in memory is available to the script when it runs.
So if you don’t want to write a module but you do want some code available in your Powershell console (session) just Dot Source it.