-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentation
More file actions
50 lines (42 loc) · 1.79 KB
/
documentation
File metadata and controls
50 lines (42 loc) · 1.79 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
Import-Module AWSPowerShell
function Send-S3Files {
<#
.SYNOPSIS
Send the files from a local path to AWS S3
.DESCRIPTION
The function will copy all files from a specific path to AWS S3
.EXAMPLE
Send-S3Files -BucketName 'backups' -Region 'sa-east-1' -AKey '####' -SKey '####' -LocalSource 'c:\temp' , 'd:\backups'
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage='Name of the bucket in AWS')][string]$BucketName
, [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage='Region used in AWS')][string]$Region
, [Parameter(Mandatory=$True, HelpMessage='AWS access key')][string]$Akey
, [Parameter(Mandatory=$True, HelpMessage='AWS secret key')][string]$SKey
, [Parameter(Mandatory=$True, ValueFromPipeline=$False, HelpMessage='Local machine paths')][string[]]$LocalSource
)
process {
Initialize-AWSDefaultConfiguration -AccessKey $AKey -SecretKey $SKey -Region $region
foreach($source in $sources) {
Set-Location $source
$files = Get-ChildItem '*.*' | Select-Object -Property Name #get all files in the folder
try {
if(Test-S3Bucket -BucketName $bucket) {
foreach($file in $files) {
if(!(Get-S3Object -BucketName $bucket -Key $file.Name)) {
Write-Host "Copying file : $file "
Write-S3Object -BucketName $bucket -File $file.Name -Key $file.Name -CannedACLName private -region $region
}
}
} Else {
Write-Host "The bucket $bucket does not exist."
}
} catch {
Write-Host "Error uploading file $file"
$Error
}
}
}
}
Write-S3Object -BucketName 'acloudguru-nfl' -Key 'testImage' -File 'C:\...' -Recurse