Reputation: 1
I wanted to make a script which there is a backup folder that has numbered folders and there are numbered zip files and for these zip files find the numbered folder and copy it there and expand it.
$R = "136" ; "287"
gci "\\rossfsscan\scanning\ejbackup\" | where-object {$_.name -match "$R"}
But i didn't know how to move the file to the matched directory.
Upvotes: 0
Views: 102
Reputation: 4694
Don't use the semicolon (;
) as it means statement termination in Powershell. So, if you were to just run the variable $R
, the only output you would get is "136". You're currently saving just the string "136" to $R
and displaying "287" to the host. Instead use the pipe symbol (|
) as a regex separator for matching.
$R = "136|287"
gci "\\rossfsscan\scanning\ejbackup\" -Recurse | Where-Object {$_.Name -match $R}
Now, when filtering, using the pipeline is okay to do so but, it tends to be slower due to the nature of how it works. Best practice is to filter as far left as you can:
gci "\\rossfsscan\scanning\ejbackup\" -Recurse -Include '*136*','*287*'
For you to copy the filtered items, pipe it to a Copy-Item
.
gci "\\rossfsscan\scanning\ejbackup\" -Recurse -Include '*136*','*287*' | Copy-Item -Destination "C:\My\destination\path"
Upvotes: 2