简体   繁体   中英

Uploading to an Amazon S3 bucket with PowerShell Core

I have a script that works perfectly to upload to an S3 bucket with Windows PowerShell, but it doesn't work with PowerShell Core. According to Amazon, most of the cmdlets that work in one should work in the other.

This is the command I'm using:

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

Again, when I try to run the command directly PowerShell it works as expected, but in PowerShell Core I get this error:

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

For PowerShell Core you will need to explicitly import the AWSPowerShell.NetCore module before your script or command runs. Due to the large number of cmdlets (over 5000 currently) in the module we cannot at present list the exported cmdlet names in the module manifest and are exploring other alternatives (such as in future creating per-service modules, but no ETA yet).

Assuming a 'clean' machine, then

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

Should then work for you. Of course if you already have the correct module installed then you can skip the first command. I set up my PowerShell profiles for both Windows and Core to always do an import.

Why this works on Windows, for some, is that up until mid last year we did list the exported cmdlets in the manifest. Right when we passed the 4000 cmdlets count in the module however, publishing to the PowerShell Gallery blocked due to a hidden limit and forced us to stop listing them. With the exported cmdlets listed in a manifest, PowerShell doesn't need an explicit import statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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