-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoogleTakeout.ps1
163 lines (141 loc) · 7.71 KB
/
GoogleTakeout.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
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
#image and video formats
$ImgFormats = @("*.jpg", "*.jpeg", "*.png", "*.webp", "*.bmp", "*.tif", "*.tiff", "*.svg", "*.heic")
$VidFormats = @("*.mp4", "*.gif", "*.mov", "*.webm", "*.avi", "*.wmv", "*.rm", "*.mpg", "*.mpe", "*.mpeg", "*.m4v")
#setup for simulation by default
[bool] $SimulateMove = $true
#clear the console
clear
#check what to move videos or images
$ImgOrVid = Read-Host "To move images input 'img' (without quotes). To Move Videos input 'vid' (without quotes), press enter when done."
$ImgOrVid = $ImgOrVid.ToLower()
#only proceed if img or vid was input
if($ImgOrVid -eq "img" -or $ImgOrVid -eq "vid"){
#get source and destination paths for the move
$SourcePath = Read-Host "Please provide source path (starting folder) to search for images or videos. Note, this path (folder) and all folders under it will be searched."
Write-Host ""
Write-Host "You input: SourcePath = $SourcePath."
Write-Host ""
write-host "If this is NOT correct, press CTRL+C to exit the script then re-excute the script and give the correct SourcePath."
Write-Host ""
Write-Host "Hit ENTER to continue."
Read-Host
$DestinationPath = Read-Host "please provide destination path to move the files to."
Write-Host ""
Write-Host "DestinationPath = $DestinationPath"
Write-Host ""
write-host "If this is NOT correct, press CTRL+C to exit the script then re-excute the script and give the correct DestinationPath."
Write-Host ""
Write-Host "Hit ENTER to continue."
Read-Host
#check that paths are not blank, in later code check that the paths are valid
if($SourcePath -eq $null -or $SourcePath -eq "" -or $DestinationPath-eq $null -or $DestinationPath -eq ""){
Write-Host "Please input a valid path for the source/destination path. Exiting script, please re-execute the script and try again."
exit
}
#check if user wants to do a simulated move or an actual move
Write-Host "Would you like to simulate a move (eg test run) or do an actual move?"
Write-Host ""
$SimulationOrNot = Read-host "For simulation input 'simulation' (without quotes). To do an actual move of your images and videos, input 'actual' (without quotes), then press enter."
#check to see if it will be a simulation or actual move
#this will be used later to figure out which command to run
if($SimulationOrNot -eq "simulation"){
$SimulateMove = $true
}elseif($SimulationOrNot -eq "actual"){
$SimulateMove = $false
}else{
Write-Host "You input an incorrect option. Exiting script, please re-run the script and try again."
exit
}
#check if paths are valid
$SourcePathExists = test-path $SourcePath
$DestinationPathExists = test-path $DestinationPath
if($SourcePathExists -and $DestinationPathExists){
#for image
if ($ImgOrVid -eq "img")
{
try{
#start logging into script directory
Start-Transcript -Path "$PSScriptRoot\$(get-date -format 'MM-dd-yyyy \HourHH\minm\sec\ss').txt" -Force
#get all images
$Contents = Get-ChildItem -Path $SourcePath -Recurse -Include $ImgFormats
#run through images and move them or simulate a move
foreach($Item in $Contents)
{
if($SimulateMove){
Move-Item -path $Item.FullName -Destination $DestinationPath -WhatIf
}
else{
Move-Item -path $Item.FullName -Destination $DestinationPath
}
Write-Host "Moving From:" $item.FullName
#fix for '$DestinationPath "\" $item.PSChildName' since this was appending back the fullpath
$MovedToDestinationPath = $DestinationPath + "\" + $item.PSChildName
Write-Host "Moving to:" $MovedToDestinationPath
Write-Host 'Time logged: '(get-date -format 'MM-dd-yyyy \HourHH\minm\sec\ss')
Write-Host ""
#progressbar
[int]$currentItem = [array]::indexof($Contents,$Item)
Write-Progress -Activity "Moving files" -Status "Currently Moving - $($Item.Name) - File $($currentItem) of $($Contents.Count - 1)
$([math]::round((($currentItem + 1)/$Contents.Count),2) * 100)% " -PercentComplete $([float](($currentItem + 1)/$Contents.Count) * 100)
Start-Sleep -Milliseconds 100
}
#stop logging
Stop-Transcript
Invoke-Item $DestinationPath
}
catch{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host "Error occured: $ErrorMessage"
Write-Host "Excepton: $FailedItem"
}
finally{
Stop-Transcript
}
}
#for video
if ($ImgOrVid -eq "vid")
{
try{
Start-Transcript -Path "$PSScriptRoot\$(get-date -format 'MM-dd-yyyy \HourHH\minm\sec\ss').txt" -Force
$Contents = Get-ChildItem -Path $SourcePath -Recurse -Include $VidFormats
foreach($Item in $Contents)
{
if($SimulateMove){
Move-Item -path $Item.FullName -Destination $DestinationPath -WhatIf
}
else{
Move-Item -path $Item.FullName -Destination $DestinationPath
}
Write-Host "Moving From:" $item.FullName
#fix for '$DestinationPath "\" $item.PSChildName' since this was appending back the fullpath
$MovedToDestinationPath = $DestinationPath + "\" + $item.PSChildName
Write-Host "Moving to:" $MovedToDestinationPath
Write-Host 'Time logged: '(get-date -format 'MM-dd-yyyy \HourHH\minm\sec\ss')
Write-Host ""
[int]$currentItem = [array]::indexof($Contents,$Item)
Write-Progress -Activity "Moving files" -Status "Currently Moving - $($Item.Name) - File $($currentItem) of $($Contents.Count - 1)
$([math]::round((($currentItem + 1)/$Contents.Count),2) * 100)% " -PercentComplete $([float](($currentItem + 1)/$Contents.Count) * 100)
Start-Sleep -Milliseconds 100
}
Stop-Transcript
}
catch{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host "Error occured: $ErrorMessage"
Write-Host "Excepton: $FailedItem"
}
finally{
Stop-Transcript
}
}
}else{
Write-Host "Either the sourcepath or desntination path you provided does not exist. Exititing script, please re-execute the script and try again."
exit
}
}
else{
Write-Host "You need to input 'img' for image or 'vid' for video. Exititing script, please re-execute the script and try again."
exit
}