Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

Hey PowerShell Guy !, How Can I Copy Files Based on Multiple Criteria?

A Translation of the Scripting Guys post : How Can I Copy Files Based on Multiple Criteria? VbScript example,

As mostly in this series I point to the original Article for more information.

dir c:\Scripts |? {$_ -match "^FS|^CG|^GPS." -and $_.CreationTime -gt (get-date).AddDays(-1)} | copy -dest C:\Test

And on the Scripting Guy's remark in the article :

2) with Windows PowerShell 1.0 we wouldn’t be able to run this script against a remote computer. 

not really as we can just as easy use UNC paths in the command ;-p 

dir \\server\c$\scripts .....

or of course by using WMI  as in the Vbscript example

* Update * OK, I could not resist here is the WMI oneliner, doing exactly the same as the Scripting Guy's VbSCript version :

([WmiSearcher]"ASSOCIATORS OF {\\.\root\cimv2:Win32_Directory.Name='C:\Scripts'} Where ResultClass = CIM_DataFile").Get() |? {$_.ConvertToDateTime($_.CreationDate) -gt (get-date).AddDays(-1) -and $_.FileName -match "^FS|^CG|^GPS." } |% {$_.copy(("c:\test\{0}.{1}" -f $_.filename,$_.Extension))}

Enjoy,

Greetings /\/\o\/\/

Published Thursday, June 26, 2008 5:50 PM by MoW
Filed under: ,

Comments

# Interesting Finds: June 27, 2008

Friday, June 27, 2008 10:14 AM by Jason Haley
Anonymous comments are disabled