繁体   English   中英

使用PowerShell Core上传到Amazon S3存储桶

[英]Uploading to an Amazon S3 bucket with PowerShell Core

我有一个脚本,可以完美地使用Windows PowerShell上传到S3存储桶,但不适用于PowerShell Core。 根据Amazon的说法,在一个中起作用的大多数cmdlet应该在另一个中起作用。

这是我正在使用的命令:

Write-S3Object -BucketName $bucketName -Folder $localDir -KeyPrefix $targetFolder -AccessKey $accessKey -SecretKey $secretKey -Recurse

同样,当我尝试直接运行命令PowerShell时,它可以按预期工作,但是在PowerShell Core中,出现此错误:

Write-S3Object : The term 'Write-S3Object' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Write-S3Object -BucketName "cloud-storage-poc" -Folder "C:\Users\Admi ...
+ ~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Write-S3Object:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

对于PowerShell Core,您需要在脚本或命令运行之前显式导入AWSPowerShell.NetCore模块。 由于模块中的cmdlet数量众多(当前超过5000个),我们目前无法在模块清单中列出导出的cmdlet名称,并正在探索其他替代方法(例如,在将来创建按服务的模块中,但尚未建立ETA)。

假设有一台“干净”的机器,那么

Install-Module AWSPowerShell.NetCore
Import-Module AWSPowerShell.NetCore
Write-S3Object ...

然后应该为您工作。 当然,如果您已经安装了正确的模块,则可以跳过第一个命令。 我将Windows和Core的PowerShell配置文件都设置为始终进行导入。

对于某些人来说,这在Windows上起作用的原因是直到去年中旬,我们才在清单中列出了导出的cmdlet。 就在我们通过模块中的4000个cmdlet计数时,由于隐藏的限制,发布到PowerShell画廊被阻止,并迫使我们停止列出它们。 清单中列出了导出的cmdlet,PowerShell不需要显式的import语句。

暂无
暂无

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

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