Hituptony
Hituptony

Reputation: 2860

Copy-Item Combine 2 statements into 1

How can I put this command into one statement in powershell?

copy-item $temp\tst1.cms $orig
copy-item $temp\tst2.cms $orig

what if names are not sequential? like

oadmrwc.cms
oadmrwn.cms

I'm trying to turn a batch script into a powershell script

Upvotes: 1

Views: 128

Answers (3)

Roman Kuzmin
Roman Kuzmin

Reputation: 42033

Parameters -Path and -LiteralPath are arrays [string[]]. So we can specify several items in one command:

copy-item $temp\tst1.cms, $temp\tst2.cms $orig

Upvotes: 1

mjolinor
mjolinor

Reputation: 68273

Something like this should work (using wildcard blobbing with Get-Childitem)

Get-Childitem $temp\tst[12].cms | Copy-Item $orig

or:

 Get-Childitem $temp\oadmrw[cn].cms | Copy-Item $orig

Upvotes: 1

LDJ
LDJ

Reputation: 7304

Would something like this suit?

$orig = "c:\temp\"
$items = "one.txt","two.txt", "three.txt","four.txt"

$items | ForEach-Object { Copy-Item $_ $orig}

You could put as many items as you want in the $items array then...

Upvotes: 2

Related Questions