Powershell写入AWS S3 [英] Powershell writing to AWS S3
问题描述
我正在尝试使用Powershell将结果写入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
推荐答案
您似乎对>>
有问题,请注意您无法将write-host函数结果传递给另一个命令.
Looks like you have an issue with >>
be aware that you can't pass the write-host function result into another command.
为此,您需要将所需的字符串分配给变量,然后将其传递到 -Content
.
In order to do that, you need to assign the string you want into a variable and then pass it into the -Content
.
看看下面的代码片段:
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
如何创建新的AccessKey和SecretKey-管理您的AWS账户的访问密钥.
How to create new AccessKey and SecretKey - Managing Access Keys for Your AWS Account.
这篇关于Powershell写入AWS S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!