-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommon.ps1
More file actions
43 lines (36 loc) · 1.55 KB
/
Common.ps1
File metadata and controls
43 lines (36 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env pwsh
# Common utilities used in other scripts.
# https://github.com/ajgorhoe/IGLib.modules.IGLibScriptsPS.git
# Internal use.
# Checks whether the specified script has already run, by using the variable
# where the script stores its location, and the current location of the script.
# If the script has already been executed, an informative message is printed to
# the standard output.
# $NotedScriptPath: must be set to the script path stored in a variable by the script.
# $ScriptPath: Must be set to actual path of the current script.
function CheckScriptExecuted($NotedScriptPath, $ScriptPath)
{
if ("$NotedScriptPath" -eq "") { return; }
$ScriptFile = $(Split-Path "$ScriptPath" -Leaf)
if ("$NotedScriptPath" -ne "")
{
if ( "$((Resolve-Path($NotedScriptPath)).Path)" -eq
"$(Resolve-Path($ScriptPath))" )
{
Write-Host "`nThe script has already been executed, refreshing definitions: $ScriptFile`n"
} else
{
Write-Host "`nWarning: Script has already been called from a different location: $ScriptFile"
Write-Host "Previous location: $NotedScriptPath"
Write-Host "Current location: $ScriptPath`n"
}
}
}
# Check whether the current script has already been executed before:
CheckScriptExecuted $ExecutedScriptPath_Common $MyInvocation.MyCommand.Path;
# Store scritp path in a variable in order to enable later verifications:
$ExecutedScriptPath_Common = $MyInvocation.MyCommand.Path
# Auxiliary definitions:
Set-Alias print Write-Host
Set-Alias alias Set-Alias
Set-Alias aliases Get-Alias