Hi, I was looking into copying data from a local drive to a shared folder via PowerShell script that will run every week via Task scheduler.
Is there anyone who can help with the PowerShell script or a VBScript?
Thanks
Hi, I was looking into copying data from a local drive to a shared folder via PowerShell script that will run every week via Task scheduler.
Is there anyone who can help with the PowerShell script or a VBScript?
Thanks
Are you trying to copy all files from the local drive, all files from a folder on the local drive, or only certain file types?
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
Waqkas,
I hope all is well. There are many, many ways to do this, but the simplest approach would be to use the copy-item
powershell cmdlet.
A simple script would look something like this, but to Mike's point/question, as we are not sure what you are copying, from where, and to what, you would need to modify as the situation requires:
Copy-Item -Path <put path here> -Filter <*.jpg> -Destination <put path here> –Recurse
You could use the Windows Task schedule to run as often as necessary.
Check out the following for ideas and documentation on how to use copy-item:
Good Luck!!
Cheers,
Adam
@Mike-Rodrick Hi, I am trying to copy a folder (which contains word docs etc..) from a local drive to a shared folder on the network. I just need to schedule this to run weekly.
Hey Waqkas,
Try something like this...
First, create your script to copy the files...
Get-ChildItem -Path D:\VMShare\Scripts -Recurse | `
ForEach-Object {Copy-Item -Path $_.FullName -Destination \\server01\Data}
This script will copy all files from the local path D:\VMShare\Scripts to the shared folder \server01\data.
Save that script to a local directory, like c:\Scripts
Then create a new basic scheduled task using task scheduler
This will launch PowerShell and then run the script.
Things to keep in mind:
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
@Adam-Gordon @Mike-Rodrick Brilliant, that works. Thanks for the help.
@Mike-Rodrick I was wondering is there a way to only copy across changes made to files/folder instead of copying the whole folder when the schedule runs? For e.g. looking at the timestamp or something similar.
Thanks
You can do this with PowerShell, and you know how I like to write scripts, lol. In this case however, there is an easier way. Robocopy has these type of options built-in. Why reinvent the wheel, as they say.
robocopy D:\Src D:\Dst /xo
The /xo instructs robocopy to exclude older files, in other words, only copy new or changed files.
You would still use a PowerShell script, and schedule it the same way, you would just call Robocopy from the script, rather than use PowerShell cmdlets. What do you think?
Here is a link to Robocopy syntax:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
Here is a really nice GUI to help build a command:
http://www.tribblesoft.com/home-page/easy-robocopy/
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.