0

I'll get right to it:

My join-path idea isn't going to work here, but this is what I am trying to do within powershell.

$HOSTNAME = $env:COMPUTERNAME

powershell -Command cd B:\backup\; ./cmd.exe /c "aws s3 sync . s3://backups123/$HOSTNAME/ --dryrun"

I am attempting to take a backup of a folder that im in within powershell and send it to an s3 bucket. The issue is I have to add computername into the path, but its not passing the variable through.

Anyone have a workaround?

1
  • 1
    What exactly are you trying to achieve? Assuming your original environment is PowerShell then you are trying to run another instance of PowerShell from there and then an instance of Cmd in that? To what end? Commented Feb 28, 2019 at 18:00

1 Answer 1

1

If you use the AWS Tools for Powershell you can utilise the Write-S3Object cmdlet

$results = Get-ChildItem .\path\to\files -Recurse -Include * 
foreach ($path in $results) 
{Write-Host $path
$filename = [System.IO.Path]::GetFileName($path)
Write-S3Object -BucketName my-bucket -File $path -Key subfolder/$env:COMPUTERNAME/$filename -CannedACLName Private -AccessKey accessKey -SecretKey secretKey}

Credit to https://volkanpaksoy.com/archive/2014/12/04/uploading-files-to-s3-using-windows-powershell/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.