簡體   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