-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOneDriveConsolidate.PS1
101 lines (88 loc) · 3.63 KB
/
OneDriveConsolidate.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
# ***************************************************************************
#
# Purpose: One Drive Consolidate and Wait for Sync
#
# ------------- DISCLAIMER -------------------------------------------------
# This script code is provided as is with no guarantee or waranty concerning
# the usability or impact on systems and may be used, distributed, and
# modified in any way provided the parties agree and acknowledge the
# Microsoft or Microsoft Partners have neither accountabilty or
# responsibility for results produced by use of this script.
#
# Microsoft will not provide any support through any means.
# ------------- DISCLAIMER -------------------------------------------------
#
# ***************************************************************************
$ODFolderName = "OneDrive - Mauvlan"
$Source = "C:\"
$exclude_directories = @()
$IncludeType = @()
$Destination = "$env:userprofile\$ODFolderName\ODConsolidate"
$IncludeType = "*.jpg", "*.doc", "*.docx", "*.xls", "*.xlsx", "*.csv"
$exclude_directories = "c:\windows", "c:\data", "c:\program files"
$exclude_directories = $exclude_directories + $Destination
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
function ConsolidateFiles {
param($DestinationDir)
Get-ChildItem -path $Source -recurse -include $IncludeType -Exclude $exclude_directories -ErrorAction SilentlyContinue -PipelineVariable file | `
ForEach-Object {
$DestinationFile = "$DestinationDir\$(($file).Name)"
if (!(($file).DirectoryName | Select-String $exclude_directories -simple)) {
write-host "$($file).name)"
if (Test-Path $DestinationFile) {
$i = 0
while (Test-Path $DestinationFile) {
$i += 1
$DestinationFile = "$DestinationDir\$(($file).basename)$i$(($file).extension)"
}
Copy-Item -Path $file -Destination $DestinationFile -Verbose -Force
}
else {
Copy-Item -Path $file -Destination $DestinationFile -Verbose -Force
}
}
}
Write-Host "Files have successfully been copied" -ErrorAction SilentlyContinue
}
function WaitForSync {
$Status = Get-ODStatus -ByPath "C:\Users\$env:username\$ODFolderName"
if ($Status -eq "UpToDate") {
{
Write-Output "One Drive Up To Date Continuing"
Exit
}
}
elseif ($Status -eq "Syncing") {
Clear-Host
Start-Sleep 3
do {
$Status = Get-ODStatus -ByPath "C:\Users\$env:username\$ODFolderName"
Write-Output "Onedrive is"$Status
Start-Sleep 15
}
until ($Status -eq "UpToDate")
}
}
function OneDriveLibOld {
Param([string]$name)
if (-not(Get-Module -name $name)) {
if (Get-Module -ListAvailable |
Where-Object { $_.name -eq $name }) {
Copy-Item -path
Import-Module -Name $name
$true
} #end if module available then import
else { $false } #module not available
} # end if not module
else { $true } #module already loaded
}
function OneDriveLib {
Copy-Item -Path $ScriptDir\OneDriveLib.dll -Destination $env:psmodulePath -Force -Verbose
Import-Module OneDriveLib.dll
}
if (!(test-path $Destination)) {New-Item -ItemType directory -Path $Destination -Verbose}
#OneDriveLib -name "OneDriveLib"
#Import-Module .\OneDriveLib.dll
OneDriveLib
ConsolidateFiles -DestinationDir $Destination
WaitForSync