-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackupFiles_WithDateFolderName.ps1
More file actions
25 lines (19 loc) · 1.09 KB
/
Copy pathBackupFiles_WithDateFolderName.ps1
File metadata and controls
25 lines (19 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#Author: Brett Pynn
#Created: 01-15-2018
#Lang: Powershell
#Purpose: Backup text files placed on server. (Change extension type for other file types)
#Details: Makes a backup of the files put on a server that needs to be labeled with a date.
#Customize the days to add to the folder name. Use (-) to remove days.
$DaysToAdd = -1
$FolderDate = Get-Date; $FolderDate=$FolderDate.AddDays($DaysToAdd); $FolderDate.ToString('yyyy-MM-dd')
$MAPPEDDRIVELETTER = "Z:\"
#Backup - Enter your drive location
$SOURCEFOLDER="<DRIVE:>\<Folder> OR \\<SERVER>\<FOLDER>"
#Choose to use the same machine as the source or a different destination.
#Uncomment and comment which destination you want.
$DESTBACKUPFOLDER=$MAPPEDDRIVELETTER+"<FOLDER>\"+$FolderDate.ToString('yyyy-MM-dd')
#$DESTBACKUPFOLDER="<DRIVE:>\<Folder> OR \\<SERVER>\<FOLDER>"+$FolderDate.ToString('yyyy-MM-dd')
net use $MAPPEDDRIVE $SOURCEFOLDER
New-Item -Path $SOURCEBACKUPFOLDER -ItemType directory -force
Copy-Item -Path $MAPPEDDRIVELETTER+"*.txt" -Destination $SOURCEBACKUPFOLDER -force -recurse -verbose
net use $MAPPEDDRIVE /delete