-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy-MultiItem.ps1
50 lines (46 loc) · 1.33 KB
/
Copy-MultiItem.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<#
.Synopsis
Copy 1 or more items to multiple desitnations
.DESCRIPTION
Wraps `copy-item` to provide multiple destinations. Great for putting one set of files on many users home drives.
#>
function Copy-MultiItem
{
[CmdletBinding(SupportsShouldProcess=$true)]
[OutputType([System.IO.FileInfo])]
Param
(
# What to copy from
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string[]]
$Source
, # Where to copy to
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
[Alias('Target')]
[string[]]
$Path
, # Output the item copied
[switch]
$PassThru
, # Output the item copied
[switch]
$Recurse
, # Overwrite items that exist
[switch]
$Force
)
Process{
foreach ($location in $Path){
Write-Verbose "Copy $Source to $Location"
if ($PSCmdlet.ShouldProcess($Location, "Copy $Source")) {
Copy-Item -Path $Source -Destination $location -Recurse:$Recurse -PassThru:$PassThru -Force:$Force
}
}
}
}