Я хочу удалить все файлы, содержащие ключевое слово «update», из корзины S3. Следующий скрипт правильно считывает файлы, содержащие «update», но команда Remove-S3Object
удалит папку и все файлы в папке, а не только файлы, содержащие «update».
Set-AWSCredentials -AccessKey $s3AccessKey -SecretKey $s3SecretKey
$s3Contents = (Get-S3Object -BucketName "$s3Bucket" -Key "path/test/" -AccessKey $s3AccessKey -SecretKey $s3SecretKey).Key
Write-Host 'Here are the contents' $s3Contents -ForegroundColor Green
foreach($x in $s3Contents){
If($x -like '*Update*'){
(Remove-S3Object -BucketName "$s3Bucket" -Key "$x" -AccessKey $s3AccessKey -SecretKey $s3SecretKey).key
}
}
Полный файл пути следующие:
Path/user/tier1/manual-retouch/test/File1.UPDATE.jpg
Path/user/tier1/manual-retouch/test/File2.Work.jpg
Path/user/tier1/manual-retouch/test/File3.jpg
Если я добавлю -Whatif
к Remove-S3Object
, я получу следующее возвращение:
What if: Performing the operation "Remove-S3Object (DeleteObjects)" on target "".
Однако без -Whatif
скрипт powershell подскажет мне Are you sure you want to perform this action? Performing the operation "Remove-S3Object (DeleteObjects)" on target "".
4 раза и удалит все там файлы и папку.
Может кто-нибудь указать, что я делаю неправильно?