Solved

Powershell script for moving files

Posted on 2011-02-23
6
1,104 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
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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article will help you understand what HashTables are and how to use them in PowerShell.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

776 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