If you deleted the file after the previous recipe, restore it or recreate it using the steps in the previous recipe. Then,
- Open the script file that you created in the previous recipe. At the second line, type the following.
$Message = "I was dot-sourced!"
- Save the script. Do not run it yet.
- Place your cursor at the integrated console, and call the script using the call operator.
& ./hello-world
- We declared $Message and assigned a string value to it. Call the variable to see what value it contains.
$Message
Nothing.
- Now, dot-source the script. (There are two dots; one is the operator, and the other after the space is reference to the current directory.)
. ./hello-world.ps1
- Call the $Message variable again.
$Message