-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart-SQLMigration.cmd
More file actions
73 lines (66 loc) · 2.42 KB
/
Start-SQLMigration.cmd
File metadata and controls
73 lines (66 loc) · 2.42 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
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
@echo off
:: ============================================================
:: SQLMigration - Starter
:: ============================================================
:: Kopiert das Tool einmalig nach C:\ProgramData\SQLMigration
:: und startet es dann als Administrator (UAC).
::
:: Warum ProgramData?
:: - Nach UAC-Elevation ist das Netzlaufwerk (W:\) nicht mehr
:: erreichbar (Elevation laeuft unter lokalem System-Kontext)
:: - ProgramData ist AppLocker/AV-unbedenklich
:: - Nicht von Cleanup-Scripts betroffen
::
:: Verwendung:
:: Doppelklick vom Share oder UNC-Pfad genuegt.
:: Kein manuelles Kopieren durch den Admin noetig.
::
:: Rolle (optional als Parameter):
:: Start-SQLMigration.cmd Source -> startet direkt als Quellserver
:: Start-SQLMigration.cmd Target -> startet direkt als Zielserver
:: Start-SQLMigration.cmd -> Rollenauswahl per Dialog
:: ============================================================
setlocal EnableDelayedExpansion
set "SRCDIR=%~dp0"
set "LOCALDIR=%ProgramData%\SQLMigration"
set "LOCALPS=%LOCALDIR%\SQL-Migration.ps1"
set "ROLE=%~1"
echo.
echo SQLMigration - Vorbereitung
echo ============================================================
echo Quelle : %SRCDIR%
echo Ziel : %LOCALDIR%
if not "%ROLE%"=="" (
echo Rolle : %ROLE%
)
echo.
:: Zielverzeichnis anlegen falls nicht vorhanden
if not exist "%LOCALDIR%" (
mkdir "%LOCALDIR%"
if errorlevel 1 (
echo FEHLER: Verzeichnis konnte nicht angelegt werden: %LOCALDIR%
echo Bitte Script als Administrator ausfuehren.
pause
exit /b 1
)
)
:: Alle Dateien kopieren (ueberschreibt vorhandene - immer aktuelle Version)
:: /E = inkl. Unterverzeichnisse (modules\, config\)
xcopy /Y /Q /E "%SRCDIR%." "%LOCALDIR%\" >nul 2>&1
if errorlevel 1 (
echo FEHLER: Kopieren fehlgeschlagen.
echo Pruefen: Lesezugriff auf Quelle, Schreibzugriff auf Ziel.
pause
exit /b 1
)
echo Dateien bereit - starte als Administrator ...
echo.
:: Rolle als Argument weitergeben wenn angegeben
if "%ROLE%"=="" (
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
"Start-Process powershell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%LOCALPS%""' -Verb RunAs"
) else (
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ^
"Start-Process powershell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%LOCALPS%"" -Role %ROLE%' -Verb RunAs"
)
endlocal