简体   繁体   中英

Powershell writing to AWS S3

I'm trying to get powershell to write results to AWS S3 and I can't figure out the syntax. Below is the line that is giving me trouble. If I run this without everything after the ">>" the results print on the screen.

Write-host "Thumbprint=" $i.Thumbprint " Expiration Date="$i.NotAfter " InstanceID ="$instanceID.Content" Subject="$i.Subject >> Write-S3Object -BucketName arn:aws:s3:::eotss-ssl-certificatemanagement

Looks like you have an issue with >> be aware that you can't pass the write-host function result into another command.

In order to do that, you need to assign the string you want into a variable and then pass it into the -Content .

Take a look at the following code snippet:

    Install-Module AWSPowerShell
    Import-Module AWSPowerShell
    #Set AWS Credential        
    Set-AWSCredential -AccessKey "AccessKey" -SecretKey "SecretKey"        

    #File upload
    Write-S3Object -BucketName "BucketName" -Key "File upload test" -File "FilePath"

    #Content upload
    $content = "Thumbprint= $($i.Thumbprint) Expiration Date=$($i.NotAfter) InstanceID = $($instanceID.Content) Subject=$($i.Subject)"
    Write-S3Object -BucketName "BucketName" -Key "Content upload test" -Content $content 

How to create new AccessKey and SecretKey - Managing Access Keys for Your AWS Account .

AWSPowerShell Module installation.

AWS Tools for PowerShell - S3 Documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM