-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfunction-ReplaceBatchVariables-example.ps1
More file actions
33 lines (29 loc) · 1.19 KB
/
function-ReplaceBatchVariables-example.ps1
File metadata and controls
33 lines (29 loc) · 1.19 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
#-----------------------------------------------------------[Functions]------------------------------------------------------------
function ReplaceBatchVariables {
param (
[parameter(
Mandatory=$true,
Position=0)
]
[string] $StringPath
)
# Replace all batch variables
if ($StringPath -match "%ALLUSERSPROFILE%") {
$StringPath = $StringPath.Replace("%ALLUSERSPROFILE%", "$env:ALLUSERSPROFILE")
}
elseif ($StringPath -match "%windir%") {
$StringPath = $StringPath.Replace("%windir%", "$env:windir")
}
elseif ($StringPath -match "%SystemRoot%") {
$StringPath = $StringPath.Replace("%SystemRoot%", "$env:systemroot")
}
elseif ($StringPath -match "%PROGRAMFILES%") {
$StringPath = $StringPath.Replace("%PROGRAMFILES%", "$env:PROGRAMFILES")
}
elseif ($StringPath -match "%ProgramData%") {
$StringPath = $StringPath.Replace("%ProgramData%", "$env:ProgramData")
}
return $StringPath
}
#-----------------------------------------------------------[Execution]------------------------------------------------------------
ReplaceBatchVariables -StringPath $MsDefenderExclusionItem