Powershell writing to AWS S3

妖精的绣舞 提交于 2021-02-11 13:01:55

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/58154852/powershell-writing-to-aws-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!