1

Have a script which search a given network location for specific file based on a given word. I need to adapt this and get the script to copy the file to another given network location.

Can someone help?

"`n" 
write-Host "Search Running" -ForegroundColor Red
$filePath = "\\fileserver\mylocation$\folder"
"`n" 

Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $false) -and  ( $_.Name -like "*keyword*" 
 ) } | Select-Object Name,Directory,CreationTime,LastAccessTime,LastWriteTime | Export-Csv "C:\scripts\searches\csv\27022014.csv" -notype
2
  • 1
    Have you tried anything, or done any research (like running get-help move-item) Commented Feb 27, 2014 at 14:20
  • I thought I could use that but with being a bit of a noob to PS I am unsure how I can add this part into my current script. Commented Feb 27, 2014 at 14:37

1 Answer 1

2

Spend some time looking at the documentation on Copy-Item. Run man copy-item -full at the prompt. Look at the examples at the bottom on the help.

Then modify your script to something like this:

Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue | 
    Where-Object {!$_.PSIsContainer -and  ($_.Name -like "*keyword*") } |
    Copy-Item -Dest \\fileserver2\difflocation
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, figured the rest. Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.