-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoteFileCopy.bat
193 lines (143 loc) · 5.73 KB
/
RemoteFileCopy.bat
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
@echo off
setlocal enabledelayedexpansion
REM Prompts the user to input the source device name, destination device name, and employee ID.
REM Validates the input by checking the length and formatting of each entry.
REM - For device names, it ensures the length is either 7 or 9 characters, and appends 'DE' if the length is 7.
REM - For employee IDs, it checks for specific length constraints (6, 7, or 9 characters) and validates the format (e.g., ends with 'a' for 7-character IDs, starts with 't2.' for 9-character IDs).
REM If any input is invalid, the user is prompted to re-enter the information.
:GetSourceDeviceName
set /p sourceDeviceName="Enter the source's device name: "
set length=0
for /l %%i in (0,1,9) do (
if "!sourceDeviceName:~%%i,1!"=="" (
goto :StopCountingSourceDeviceName
)
set /a length+=1
)
:StopCountingSourceDeviceName
if !length!==7 (
set sourceDeviceName=DE!sourceDeviceName!
) else if !length!==9 (
if /i not "!sourceDeviceName:~0,2!"=="de" (
echo Error: Invalid device name.
goto :GetSourceDeviceName
)
) else (
echo Error: Invalid device name.
echo.
goto :GetSourceDeviceName
)
:GetDestinationDeviceName
set /p destinationDeviceName="Enter the destination device name: "
set length=0
for /l %%i in (0,1,9) do (
if "!destinationDeviceName:~%%i,1!"=="" (
goto :StopCountingDestinationDeviceName
)
set /a length+=1
)
:StopCountingDestinationDeviceName
if !length!==7 (
set destinationDeviceName=DE!destinationDeviceName!
) else if !length!==9 (
if /i not "!destinationDeviceName:~0,2!"=="de" (
echo Error: Invalid device name.
goto :StopCountingDestinationDeviceName
)
) else (
echo Error: Invalid device name.
echo.
goto :StopCountingDestinationDeviceName
)
:GetEmployeeID
set /p employeeID="Enter the employee ID: "
set length=0
for /l %%i in (0,1,9) do (
if "!employeeID:~%%i,1!"=="" (
goto :StopCountingEmployeeID
)
set /a length+=1
)
:StopCountingEmployeeID
if not !length!==6 (
if !length!==7 (
if /i not "!employeeID:~-1!"=="a" (
echo Error: Invalid employee ID.
goto :GetEmployeeID
)
) else if !length!==9 (
if /i not "!employeeID:~0,3!"=="t2." (
echo Error: Invalid employee ID.
goto :GetEmployeeID
)
) else (
echo Error: Invalid employee ID.
echo.
goto :GetEmployeeID
)
)
REM Checks if both the source and destination devices are accessible on the network and verifies the existence of the user profile on each device.
REM If either the device cannot be accessed remotely or the user's profile directory does not exist, an error message is displayed and the script exits.
echo.
echo Check whether the devices are recognized on the network and the user profile exists on both devices.
echo ... checking !sourceDeviceName!
set workingSourcePath=\\!sourceDeviceName!\C$\
if not exist "!workingSourcePath!" (
echo Error: !sourceDeviceName! not found.
goto :ExitOnError
)
set workingSourcePath=!workingSourcePath!Users\!employeeID!\
if not exist "!workingSourcePath!" (
echo Error: !employeeID! does not exist on !sourceDeviceName!.
goto :ExitOnError
)
echo ... checking !destinationDeviceName!
set workingDestinationPath=\\!destinationDeviceName!\C$\
if not exist "!workingDestinationPath!" (
echo Error: !destinationDeviceName! not found.
goto :ExitOnError
)
set workingDestinationPath=!workingDestinationPath!Users\!employeeID!\
if not exist "!workingDestinationPath!" (
echo Error: !employeeID! does not exist on !destinationDeviceName!.
goto :ExitOnError
)
REM Copies user directories from the source device to the destination device and excludes specified files and directories.
echo.
echo Copying files and sub-directories
robocopy !workingSourcePath! !workingDestinationPath! /E /J /NJH /NJS /XF NTUSER.DAT ntuser.dat.LOG1 ntuser.dat.LOG2 ^
/XX /XD "Contacts" "Favorites" "Links" "Pictures" "Videos" "Searches" "Saved Games" "Music" ".cisco" ".ms-ad" ^
"AppData" "Application Data" "Cookies" "Local Settings" "NetHood" "PrintHood" "SendTo" "Templates" "Recent" "Start Menu" ^
"OneDrive" "OneDrive - Advocate Health"
REM Copies browser bookmarks from the source device to the destination device for Microsoft Edge and Google Chrome.
echo.
echo Copying browser bookmarks
set edgeFavoritesPath="AppData\Local\Microsoft\Edge\User Data\Default\Bookmarks"
set chromeBookmarksPath="AppData\Local\Google\Chrome\User Data\Default\Bookmarks"
if exist "!workingSourcePath!!edgeFavoritesPath!" (
xcopy !workingSourcePath!!edgeFavoritesPath! !workingDestinationPath!!edgeFavoritesPath! /E /C /-I /Q /Y /J >nul
echo Warning: If Microsoft Edge was open, user may need to re-launch application for changes to take affect.
echo Warning: User will need to show favorites in Microsoft Edge.
) else (
echo Warning: No Microsoft Edge favorites found on the source device.
)
if exist "!workingSourcePath!!chromeBookmarksPath!" (
xcopy !workingSourcePath!!chromeBookmarksPath! !workingDestinationPath!!chromeBookmarksPath! /E /C /-I /Q /Y /J >nul
echo Warning: If Google Chrome was open, user may need to re-launch application for changes to take affect.
) else (
echo Warning: No Google Chorme bookmarks found on the source device.
)
goto :ExitOnSuccess
REM This section handles the script's completion by either confirming success or handling errors.
REM If the script completes successfully, it prints a success message and ends the local environment.
REM If an error occurs, it simply ends the local environment without further action.
:ExitOnSuccess
echo.
echo Remote copy is completed.
echo.
echo WARNING: Does the user need OneDrive set up on the destination computer?
echo WARNING: Does the user need to configure their Microsoft OneNote?
echo WARNING: Does the user need to map any networked printers?
endlocal
:ExitOnError
endlocal