简体   繁体   English

Powershell 写入 AWS S3

[英]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.我试图让 powershell 将结果写入 AWS S3,但我无法弄清楚语法。 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.看起来您对>>有疑问,请注意您无法将写入主机 function 结果传递给另一个命令。

In order to do that, you need to assign the string you want into a variable and then pass it into the -Content .为此,您需要将所需的字符串分配给变量,然后将其传递给-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 .如何创建新的 AccessKey 和 SecretKey - 为您的 AWS 账户管理访问密钥

AWSPowerShell Module installation. AWSPowerShell 模块安装。

AWS Tools for PowerShell - S3 Documentation. 适用于 PowerShell 的 AWS 工具 - S3 文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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