Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell script for moving files

Posted on 2011-02-23
6
Medium Priority
?
1,113 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  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 750 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 750 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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

715 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