| | 0

PowerShell: Including Scripts, Functions and Modules

This post is about including PowerShell scripts, functions and modules to the active session or to another script. First we need a simple script that we will save as Hello-World.ps1.

1
$Date = Get-Date -Format yyyy-MM-dd
1
$Time = Get-Date -Format HH:mm
1
1
Write-Output "Hello World"
1
Write-Output "[Date] $Date"
1
Write-Output "[Time] $Time"

Run a PowerShell Script

Okay. Now let’s start the script:

1
2
3
4
5
PS D:\Scripts\> .\Hello-World.ps1
Hello World
[Date] 2013-11-17
[Time] 17:05
PS D:\Scripts\>

Not very exciting: the script has been executed! This way we also can call a script from within another scipt.

Dot-Sourcing

Let’s call the script again, but this time we use “Dot-Sourcing”, which is done by an additional dot (and a space) before the command:

<The full post is only available in German>