-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobalFunctions.ps1
More file actions
30 lines (25 loc) · 847 Bytes
/
GlobalFunctions.ps1
File metadata and controls
30 lines (25 loc) · 847 Bytes
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
### Globally defined functions are called from here and will be imported into all launched dashboards.
function New-Scriptblock {
param (
[Parameter(Mandatory=$false)][string]$String = "",
[Parameter(Mandatory=$false)][string]$Path = ""
)
$code = if ($String -ne "") {
$String
} elseif (Test-Path $Path) {
(Get-Content -Path $Path -Raw)
} else {""}
$scriptBlock = [scriptblock]::Create($code)
return $scriptBlock
}
function New-Function {
param (
[Parameter(Mandatory=$true)][string]$Name,
[Parameter(Mandatory=$true)][string]$scriptBlock
)
if ($Name -notmatch "\s") {
Set-Item -Path "function:global:$Name" -Value $scriptBlock
} else {
Write-Host "ERROR: function names cannot contain spaces" -ForegroundColor Red
}
}