-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathGet-EnvPath.ps1
More file actions
43 lines (33 loc) · 929 Bytes
/
Get-EnvPath.ps1
File metadata and controls
43 lines (33 loc) · 929 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
31
32
33
34
35
36
37
38
39
40
41
42
43
##############################################################################
##
## Invoke-CmdScript
##
## From PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################
<#
.SYNOPSIS
Invoke the specified batch file (and parameters), but also propagate any
environment variable changes back to the PowerShell environment that
called it.
.EXAMPLE
PS > type foo-that-sets-the-FOO-env-variable.cmd
@set FOO=%*
echo FOO set to %FOO%.
PS > $env:FOO
PS > Invoke-CmdScript "foo-that-sets-the-FOO-env-variable.cmd" Test
C:\Temp>echo FOO set to Test.
FOO set to Test.
PS > $env:FOO
Test
#>
param (
[string]$filename
)
$env:Path -split ";" | Where-Object {
Test-Path -Path (Join-Path -Path $_ -ChildPath $filename) -PathType Leaf
} | ForEach-Object {
echo (Join-Path -Path $_ -ChildPath $filename)
return;
}