-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathTest-2-workaround.ps1
33 lines (25 loc) · 964 Bytes
/
Test-2-workaround.ps1
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
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Definition
$Source = "$PSScriptRoot\1"
$Target = "$PSScriptRoot\2"
# remove test files, create result collector
Remove-Item $Source, $Target -Force -Recurse -ErrorAction 0
$log = New-Object System.Collections.Specialized.OrderedDictionary
# make test input, a source directory and a file in it
$null = mkdir $Source
42 > "$Source\test.txt"
# this is the workaround copy
function Test-Workaround {
# workaround step 1, ensure the destination directory
$null = mkdir $Target -Force
# workaround step 2, copy not "source" but "all from source"
Copy-Item -Path $Source\* -Destination $Target -Recurse -Force
}
# test workaround with no target files
Test-Workaround
$log.files1 = Get-ChildItem $Target -Recurse -Name
# test workaround with target files
Test-Workaround
$log.files2 = Get-ChildItem $Target -Recurse -Name
# remove test files, output results
Remove-Item $Source, $Target -Force -Recurse
$log