forked from directorcia/Office365
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patho365-getrepo.ps1
65 lines (49 loc) · 2.42 KB
/
o365-getrepo.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
<# CIAOPS
Script provided as is. Use at own risk. No guarantees or warranty provided.
Description - Download all contents of /directorcia/office365 repository from GitHub
Source - https://github.com/directorcia/Office365/blob/master/o365-getrepo.ps1
Original concept - https://gist.github.com/chrisbrownie/f20cb4508975fb7fb5da145d3d38024a
Prerequisites = 0
More scripts available by joining http://www.ciaopspatron.com
#>
## Variables
$systemmessagecolor = "cyan"
$processmessagecolor = "green"
$errormessagecolor = "red"
$Owner = "directorcia" ## Repository owner
$Repository = "Office365" ## Repository name
$Path = "" ## Subfolder within Repository if required
$DestinationPath = "C:\downloads\repo\" ## Location for local copy of repository, does not need to exist prior
## If you have running scripts that don't have a certificate, run this command once to disable that level of security
## set-executionpolicy -executionpolicy bypass -scope currentuser -force
Clear-Host
write-host -foregroundcolor $systemmessagecolor "Start Script`n"
[Net.ServicePointManager]::SecurityProtocol = "tls12,tls11,tls,ssl3" ## Avoid failure to create secure channel
$baseUri = "https://api.github.com/"
$args = "repos/$Owner/$Repository/contents/$Path"
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls,ssl3" ## Avoid failure to create secure channel
$wr = Invoke-WebRequest -Uri $($baseuri+$args)
$objects = $wr.Content | ConvertFrom-Json
$files = $objects | where {$_.type -eq "file"} | Select -exp download_url
$directories = $objects | where {$_.type -eq "dir"}
$directories | ForEach-Object {
DownloadFilesFromRepo -Owner $Owner -Repository $Repository -Path $_.path -DestinationPath $($DestinationPath+$_.name)
}
if (-not (Test-Path $DestinationPath)) {
# Destination path does not exist, let's create it
try {
New-Item -Path $DestinationPath -ItemType Directory -ErrorAction Stop
} catch {
throw "Could not create path '$DestinationPath'!"
}
}
foreach ($file in $files) {
$fileDestination = Join-Path $DestinationPath (Split-Path $file -Leaf)
try {
Invoke-WebRequest -Uri $file -OutFile $fileDestination -ErrorAction Stop -Verbose
"Grabbed '$($file)' to '$fileDestination'"
} catch {
throw "Unable to download '$($file.path)'"
}
}
write-host -foregroundcolor $systemmessagecolor "Script completed`n"