Solved

Powershell script for moving files

Posted on 2011-02-23
6
1,110 Views
Last Modified: 2012-05-11
Let me preface this question by stating I am new to powershell though have worked with vbscript and trying to build skills and knowledge of powershell.  Now for the question....

My father recently bought a new computer and would like to move a ton of data from one to the other.  He called me to ask about how to get around the copy crashing because of long file names and extensions.  Is there a cmdlet I could use to move this and ignore extremely long filenames or extensions?  I want it to skip any problem files.

Thanks in advance.
0
Comment
Question by:childersj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 34962463
How are you copying the files now?

For somethign like this I would use robocopy.  With powershell you can use move-item but I have not tested with large file names.

http://ss64.com/nt/robocopy.html
http://technet.microsoft.com/en-us/library/dd315310.aspx
0
 

Author Comment

by:childersj
ID: 34962488
Yea, I am famiiliar with robocopy, just hoping there was some practice here for PS scripting.  Thanks.
0
 
LVL 9

Expert Comment

by:Aeriden
ID: 34962638
There is a cmdlet called Copy-Item included with PowerShell.  Check out http://technet.microsoft.com/en-us/library/dd347638.aspx for the parameters.
0
Are You Headed to Black Hat USA 2017?

Getting ready for Black Hat next week? Kick things off with the WatchGuard Badge Challenge and test your puzzle and cipher skills. Do you have what it takes to earn our limited edition Firebox Badge? Get started today - https://crimsonthorn.net

 
LVL 4

Assisted Solution

by:karim_hashish
karim_hashish earned 250 total points
ID: 34966039
Hello

I would recommend to use the robocopy to copy all the data from the source to the destination and by the way you can use robocopy command from the powershell or the Cmd (as you like) as well as using robocopy you will avoid any problems of filenames and extension besides you will get faster copying  ~ 40 % more than any other way of copying.

Also robocopy gives you a very good summary after the whole operation is finished.

kindly find below a simple example that can fulfill you needs right away.

robocopy d:\first d:\second /move /S

d:\first ---> the source folder

d:\second ---> the destination folder

/move (optional) : to move the files insteading of copying.

/S : to include the subfolders in the operation of copying or moving.

I'll be waiting for the good news

If you have any further inquires don't hesitate to refer back.

Best Regards,

Karim


0
 
LVL 10

Accepted Solution

by:
wls3 earned 250 total points
ID: 35022655
Unforutnately, Powershell's built in move functionality is not great yet.  As is noted in this link

http://www.vistax64.com/powershell/30490-copy-item-recurse-wildcard.html

You can probably accomplish it with a Copy-Item command alone.  This won't necessarily clean up the old machines folders and files, but, it takes care of the transfer.  Typically, I can't get the *.* wildcard approach to work with the -filter option, yet, there may be a trick out that makes this flow.
0
 

Author Closing Comment

by:childersj
ID: 35138257
Thanks for the help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question