Solved

Script to Copy and Rename an Excel file Between Network Shares

Posted on 2013-12-09
6
371 Views
Last Modified: 2013-12-10
I have an XLS file that is updated once a day on a network share. The network share is \\company.com\Reports\Daily
The file name is a randomly generated file name with an *.xls extension.

I need a script that I can setup as a daily scheduled task that will:

-Take the *.xls file with the most recent last modified date located in: \\company.com\Reports\Daily folder
-Rename that file to the name: active.xls
-Copy that file to a location in: \\ServerName\Reports with the name Active.xls
(The order of bullet points 2 or 3 does not matter, the end result of the script just requires that I have the latest version of the *.xls file on the specific server with the name Active.xls)

The reason for this is I have an application at the destination server that calls for this specific file name, so in order to completely automate this process without having to manually rename the file every day, I would like this in a scheduled task script.

Thank you.
0
Comment
Question by:fireguy1125
[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
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

by:pony10us
ID: 39707057
Couple questions:

1. Will the task run once or multiple times during the day?
2. Is there a possiblity that the destination file (active.xls) be in use/open when the task runs?
0
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39707133
The following should work for you.  If the file is read-only you would want to add the -force switch to Get-ChildItem.  And if the destination file is locked you could run into an error.
Get-ChildItem \\company.com\Reports\Daily -filter *.xls | Sort -Descending -Property LastWriteTime | Select -First 1 | Copy-Item -Destination "\\company.com\Reports\active.xls" -force

Open in new window

0
 
LVL 1

Author Comment

by:fireguy1125
ID: 39707211
1. The task will run once per day, and there will not be more than one modified source file per day.
2. Destination file will not be in use.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 26

Expert Comment

by:pony10us
ID: 39707261
Are the source and destination mapped locations?
0
 
LVL 1

Author Comment

by:fireguy1125
ID: 39707558
They are not mapped, but are shared and accessible via UNC paths as noted.
0
 
LVL 1

Author Closing Comment

by:fireguy1125
ID: 39709058
Works perfectly, thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

710 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