-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEnv.ps1
More file actions
64 lines (64 loc) · 2.34 KB
/
Env.ps1
File metadata and controls
64 lines (64 loc) · 2.34 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
.SYNOPSIS
Env
Created By: Dana Meli-Wischman
Created Date: August, 2018
Last Modified Date: December 15, 2023
.DESCRIPTION
This returns the value of your environment variables.
.EXAMPLE
Env [<variable>] (without any quotes for normal variables)
Env [<'$variable'>] (with single quotes for variables from your "Variable:" drive)
.NOTES
Still under development.
#>
param([string]$myargs)
$FileVersion = "0.1.4"
if (!($myargs)) {
Say "Environment Lister $FileVersion"
Say ""
Say "Listing ALL your environment Variables."
Say "All sorted and formatted for your pleasure."
Say "-=-=-===-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
Get-ChildItem Env: | Sort-Object Name | Format-Table -Wrap -AutoSize
Say ""
Say "These are your variables on the Variable: Drive"
Say "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
Get-ChildItem variable: | Sort-Object Name | Format-Table -Wrap -AutoSize
Say "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
Say "Use `'ENV VAR`' for normal variables"
Say "Use `'ENV `$VAR`' for environment drive variables"
Say "It is okay to use Wildcards `'ENV *VAR*`' on normal variables"
Say "(The * will not expand inside of the `' single quote used on drive variables.)"
Say "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
return
}
#$TheArgs = "$myargs $args"
if ($myargs.substring(0, 1) -eq '$') {
$tmp = $myargs.substring(1)
Try { Get-ChildItem Variable:"$tmp" -ErrorAction Stop | Format-Table -Wrap -AutoSize }
catch {
Say -ForeGroundColor Red "Did not match Environment Drive Variable" $tmp.ToUpper()
Say ""
}
return
}
else {
$arg1 = $myargs.substring(0, 1).toupper() + $myargs.substring(1).tolower()
$arg2 = $myargs.toupper()
if ($arg2 -eq "PATH") {
Say
Say "Displaying the PATH variable for you"
Say "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
$Env:PATH -Split ";" | Sort-Object
return
}
Say
Say "Displaying the Environment Variable" $arg1.ToUpper() "if it exists"
try { Get-ChildItem Env:"$arg2" -ErrorAction Stop | Format-Table -Wrap -AutoSize }
catch {
Say -ForeGroundColor Red "Did not match Environment Variable" $arg1.ToUpper()
Say ""
}
return
}