Start-Transcript -Verbose -Path 'C:\temp\FileRetrieve.log'
$FileToRetrieve='<Path To File>'
$S3BucketName='<S3 Bucket Name>'
$S3AccessKey='<AWS Access Key ID>'
$S3SecretKey='<AWS Secret Key>'
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
$m = 'AWSPowerShell'
# If module is imported say that and do nothing
if (Get-Module | Where-Object {$_.Name -eq $m}) {
write-host "Module $m is already imported."
}
else {
# If module is not imported, but available on disk then import
if (Get-Module -ListAvailable | Where-Object {$_.Name -eq $m}) {
Import-Module $m -Verbose
}
else {
# If module is not imported, not available on disk, but is in online gallery then install and import
if (Find-Module -Name $m | Where-Object {$_.Name -eq $m}) {
Install-Module -Name $m -Force -Verbose -Scope CurrentUser
Import-Module $m -Verbose
}
else {
# If the module is not imported, not available and not in the online gallery then abort
write-host "Module $m not imported, not available and not in an online gallery, exiting."
EXIT 1
}
}
}
Set-ExecutionPolicy RemoteSigned -Force
Set-DefaultAWSRegion -Region us-east-1
$hn = Hostname
$keyFile = Split-Path $FileToRetrieve -leaf
$date = Get-Date -uformat %m-%d-%Y
$key = "$hn/$keyfile.$date"
Write-S3Object -BucketName $S3BucketName -File $FileToRetrieve -Key $key -CannedACLName authenticated-read -AccessKey $S3AccessKey -SecretKey $S3SecretKey
Stop-Transcript