I am writing a powershell script that will upload the filenames listed in a text file that was created by a robocopy script to an S3 bucket and I cannot seem to get the syntax write for the Write-S3Object command.
Here is my code and I'm hoping you can help me debug it:
foreach($line in Get-Content C:\Scripts\ToS3\FileList1.txt) {
if($line -match $regex){
$key = $line -replace [regex]::Escape('\\server\e$\'), '/' -replace
"c:\\", "s3://mybucket/" -replace "\\","/" -replace " `t","" -replace "`t",""
$file = $line -replace " `t","" -replace "`t",""
write-output `"$file`"
write-output `"$key`"
Write-S3Object -BucketName mybucket -File `"$file`" -Key `"$key`" -ProfileName xxxx
}
}
For whatever reason $file isn't loading properly though it displays just fine in write-output. What gives?
All of the replace commands are used to make the robocopy output:
\server\e$\Data\example folder 1\example folder 2\another file 2.txt
to S3 format:
s3://mybucket/Data/example folder 1/example folder 2/another file 2.txt
Write-S3Object doesn't understand the s3:// syntax. Simply give it the bucket name (to the -BucketName parameter) and the local filename to the -File parameter. If you don't supply a value for -Key the filename will be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With