-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup-Robocopy.ps1
76 lines (55 loc) · 2.96 KB
/
Setup-Robocopy.ps1
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
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
if(-Not(Test-Path -Path HKCR)){
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
}
if(-Not(Test-Path -Path HKCR\Directory\shell\RoboCopy)){
New-Item -path "HKCR:\Directory\shell" -Name RoboCopy
New-Item -path "HKCR:\Directory\shell\RoboCopy" -Name command -Value "powershell.exe -file $home\documents\Robocopy\setInitialLocation.ps1 %V"
}
if(-Not(Test-Path -Path HKCR\Directory\shell\RoboCut)){
New-Item -path "HKCR:\Directory\shell" -Name RoboCut
New-Item -path "HKCR:\Directory\shell\Robocut" -Name command -Value "powershell.exe -file $home\documents\Robocopy\setInitialLocationCut.ps1 %V"
}
if(-Not(Test-Path -Path HKCR\Directory\shell\RoboPaste)){
New-Item -path "HKCR:\Directory\shell" -Name RoboPaste
New-Item -path "HKCR:\Directory\shell\RoboPaste" -Name command -Value "powershell.exe -file $home\documents\Robocopy\getCopyToLocation.ps1 %V"
}
cd $home\documents
if(-Not(Test-Path -Path $home\desktop\Robocopy)){
mkdir Robocopy
New-Item -Path $home\documents\Robocopy -Name getCopyToLocation.ps1 -ItemType file -Value '
$logicalProcessor = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors
if(Test-Path -Path $home\documents\Robocopy\initial.txt -PathType Leaf){
$initial = Get-Content -Path $home\documents\Robocopy\initial.txt
$copyToLocation = "$args"
robocopy "$initial" "$copyToLocation" /S /E /MT:$logicalProcessor /NFL /eta /NDL /NJH /NJS
Remove-Item -Path $home\documents\Robocopy\initial.txt
}
ElseIf(Test-Path -Path $home\documents\Robocopy\cutInitial.txt -PathType Leaf ){
$initial = Get-Content -Path $home\documents\Robocopy\cutInitial.txt
$copyToLocation = "$args"
robocopy "$initial" "$copyToLocation" /move /S /E /MT:$logicalProcessor /eta /NFL /NDL /NJH /NJS
Remove-Item -Path $home\documents\Robocopy\cutInitial.txt
}
'
New-Item -Path $home\documents\Robocopy -Name setInitialLocation.ps1 -ItemType file -Value '
if(Test-path -Path $home\documents\Robocopy\cutInitial.txt){
rm $home\documents\Robocopy\cutInitial.txt
}
if(Test-path -Path $home\documents\Robocopy\initial.txt){
rm $home\documents\Robocopy\initial.txt
}
$setInitialLocation = "$args"
New-Item -Path "$home\documents\Robocopy" -Name "initial.txt" -ItemType "file" -Value "$setInitialLocation"
'
New-Item -Path $home\documents\Robocopy -Name setInitialLocationCut.ps1 -ItemType file -Value '
if(Test-path -Path $home\documents\Robocopy\initial.txt){
rm $home\documents\Robocopy\initial.txt
}
if(Test-path -Path $home\documents\Robocopy\cutInitial.txt){
rm $home\documents\Robocopy\cutInitial.txt
}
$getInitialCut = "$args"
New-Item -Path "$home\documents\Robocopy" -Name "cutInitial.txt" -ItemType "file" -Value "$getInitialCut"
'
}