Solved

Powershell script for moving files

Posted on 2011-02-23
6
1,103 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

26 Experts available now in Live!

Get 1:1 Help Now