forked from nightroman/PowerShellTraps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-1.ps1
More file actions
42 lines (35 loc) · 957 Bytes
/
Test-1.ps1
File metadata and controls
42 lines (35 loc) · 957 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
$v610 = $PSVersionTable.PSVersion -ge ([version]'6.0.9999')
$ErrorActionPreference = 'Stop'
# make directory with backticks, cd to it
$root = Split-Path $MyInvocation.MyCommand.Path
Set-Location -LiteralPath $root
$null = mkdir '``test``'
Set-Location -LiteralPath '``test``'
# try Get-ChildItem * in the directory with backticks
try {
# v2-v6.0.2 - fails "Cannot find path '...\`test`'
# v6.1.0-preview.3 - works here but see next
# v6.1.0-preview.4 - fails again
Get-ChildItem *
# v6.1.0-preview.3 - does not fail in the empty directory, but see next
'v6.1.0 worked'
}
catch {
$_
}
# v6.1.0
if ($v610) {
# make a file
[System.IO.File]::WriteAllText((Join-Path $root '``test``/z.txt'), 'text')
# try Get-ChildItem * again in the directory with a file
try {
# fails "Could not find item ...\`test`\z.txt"
Get-ChildItem *
}
catch {
$_
}
}
# remove test directory
Set-Location ..
Remove-Item -LiteralPath '``test``' -Force -Recurse