Solved

Powershell script for moving files

Posted on 2011-02-23
6
1,101 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now