AWS Tools for Windows PowerShell
Command Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Synopsis

Deletes one or more objects in an Amazon S3 bucket.

Syntax

WithKey (Default)

Remove-S3Object
-BucketName <String>
-Key <String>
-VersionId <String>
-RequestPayer <RequestPayer>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-ClientConfig <AmazonS3Config>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>
-ForcePathStyleAddressing <Boolean>

WithKeyVersionCollection

Remove-S3Object
-BucketName <String>
-KeyAndVersionCollection <KeyVersion[]>
-ReportErrorsOnly <SwitchParameter>
-ChecksumAlgorithm <ChecksumAlgorithm>
-RequestPayer <RequestPayer>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-ClientConfig <AmazonS3Config>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>
-ForcePathStyleAddressing <Boolean>

WithKeyCollection

Remove-S3Object
-BucketName <String>
-KeyCollection <String[]>
-ReportErrorsOnly <SwitchParameter>
-ChecksumAlgorithm <ChecksumAlgorithm>
-RequestPayer <RequestPayer>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-ClientConfig <AmazonS3Config>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>
-ForcePathStyleAddressing <Boolean>

WithS3ObjectCollection

Remove-S3Object
-InputObject <S3Object[]>
-ReportErrorsOnly <SwitchParameter>
-RequestPayer <RequestPayer>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-ClientConfig <AmazonS3Config>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>
-ForcePathStyleAddressing <Boolean>

Description

Deletes the specified object, object version or set of objects from S3. The DeleteObject operation removes the specified object from Amazon S3.Once deleted, there is no method to restore or undelete an object. You can pipe Amazon.S3.Model.S3Object or Amazon.S3.Model.S3ObjectVersion instances to this cmdlet and their members will be used to satisfy the BucketName, Key (and VersionId if an S3ObjectVersion instance is supplied) parameters.

Note: When piping a collection of Amazon.S3.Model.S3Object or Amazon.S3.Model.S3ObjectVersion instances to identify the objects to be deleted the cmdlet receives the elements from the piped collection one element at a time and will therefore make one service call per collection element to be deleted. To perform the deletion as a batch up to 1000 objects with a single call to the service specify the collection as the value of the -InputObject parameter. The -KeyCollection and -KeyAndVersionCollection parameters also automatically process as a batch and make a single call to the service to delete up to 1000 objects identified in the collections supplied to the parameters.

Parameters

-AuthenticationValue <String>
Specifies the current token/code displayed on the multi-factor authentication device associated with your AWS Account. This is a required property for this request if:
1. EnableMfaDelete was configured on the bucket containing this object's version.
2. You are deleting an object's version
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesMfaCodes_Second
-BucketName <String>
The bucket name of the bucket containing the object. Directory buckets - When you use this operation with a directory bucket, you must use virtual-hosted-style requests in the format Bucket_name.s3express-az_id.region.amazonaws.com. Path-style requests are not supported. Directory bucket names must be unique in the chosen Availability Zone. Bucket names must follow the format bucket_base_name--az-id--x-s3 (for example, DOC-EXAMPLE-BUCKET--usw2-az1--x-s3). For information about bucket naming restrictions, see Directory bucket naming rules in the Amazon S3 User Guide.Access points - When you use this action with an access point, you must provide the alias of the access point in place of the bucket name or specify the access point ARN. When using the access point ARN, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this action with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using access points in the Amazon S3 User Guide.Access points and Object Lambda access points are not supported by directory buckets.S3 on Outposts - When you use this action with Amazon S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When you use this action with S3 on Outposts through the Amazon Web Services SDKs, you provide the Outposts access point ARN in place of the bucket name. For more information about S3 on Outposts ARNs, see What is S3 on Outposts? in the Amazon S3 User Guide.
Required?True
Position?1
Accept pipeline input?True (ByValue, ByPropertyName)
-ChecksumAlgorithm <ChecksumAlgorithm>
Indicates the algorithm you want Amazon S3 to use to create the checksum for the object. For more information, see Checking object integrity in the Amazon S3 User Guide.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-ClientConfig <AmazonS3Config>
Amazon.PowerShell.Cmdlets.S3.AmazonS3ClientCmdlet.ClientConfig
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
This parameter overrides confirmation prompts to force the cmdlet to continue its operation. This parameter should always be used with caution.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-ForcePathStyleAddressing <Boolean>
S3 requests can be performed using one of two URI styles: Virtual or Path. When using Virtual style, the bucket is included as part of the hostname. When using Path style the bucket is included as part of the URI path. The default value is $true when the EndpointUrl parameter is specified, $false otherwise.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-InputObject <S3Object[]>
Collection of S3Object or S3ObjectVersion instances describing the S3 objects to be deleted.
Note: the objects must all belong to the same bucket.
Required?True
Position?Named
Accept pipeline input?True (ByValue, ByPropertyName)
AliasesInputObjects, S3ObjectCollection
-Key <String>
The object key identifying the object to be deleted.
Required?True
Position?2
Accept pipeline input?True (ByPropertyName)
-KeyAndVersionCollection <KeyVersion[]>
Collection of Amazon.S3.Model.KeyVersion objects describing the S3 objects to be deleted.
Required?True
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesVersionKeys, VersionKey
-KeyCollection <String[]>
Collection of key names describing the S3 objects to be deleted.
Required?True
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesKeys
-ReportErrorsOnly <SwitchParameter>
If set when deleting multiple objects the service response will include only those keys for objects on which the delete operation failed. By default this switch is not set and keys for both successful multi-object deletes and failures are returned in the response.This parameter is used only when deleting multiple objects using the -KeyCollection parameter.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesQuiet
-RequestPayer <RequestPayer>
Confirms that the requester knows that they will be charged for the request. Bucket owners need not specify this parameter in their requests.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-SerialNumber <String>
Specifies the serial number of the multi-factor authentication device associated with your AWS Account. This is a required property for this request if:
1. EnableMfaDelete was configured on the bucket containing this object's version.
2. You are deleting an object's version
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesMfaCodes_First
-UseAccelerateEndpoint <SwitchParameter>
Enables S3 accelerate by sending requests to the accelerate endpoint instead of the regular region endpoint. To use this feature, the bucket name must be DNS compliant and must not contain periods (.).
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-UseDualstackEndpoint <SwitchParameter>
Configures the request to Amazon S3 to use the dualstack endpoint for a region. S3 supports dualstack endpoints which return both IPv6 and IPv4 values. The dualstack mode of Amazon S3 cannot be used with accelerate mode.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-VersionId <String>
Version identifier of the S3 object to be deleted, for buckets with versioning enabled.
Required?False
Position?3
Accept pipeline input?True (ByPropertyName)

Common Credential and Region Parameters

-AccessKey <String>
The AWS access key for the user account. This can be a temporary access key if the corresponding session token is supplied to the -SessionToken parameter.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAK
-Credential <AWSCredentials>
An AWSCredentials object instance containing access and secret key information, and optionally a token for session-based credentials.
Required?False
Position?Named
Accept pipeline input?True (ByValue, ByPropertyName)
-EndpointUrl <String>
The endpoint to make the call against.Note: This parameter is primarily for internal AWS use and is not required/should not be specified for normal usage. The cmdlets normally determine which endpoint to call based on the region specified to the -Region parameter or set as default in the shell (via Set-DefaultAWSRegion). Only specify this parameter if you must direct the call to a specific custom endpoint.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-NetworkCredential <PSCredential>
Used with SAML-based authentication when ProfileName references a SAML role profile. Contains the network credentials to be supplied during authentication with the configured identity provider's endpoint. This parameter is not required if the user's default network identity can or should be used during authentication.
Required?False
Position?Named
Accept pipeline input?True (ByValue, ByPropertyName)
-ProfileLocation <String>
Used to specify the name and location of the ini-format credential file (shared with the AWS CLI and other AWS SDKs)If this optional parameter is omitted this cmdlet will search the encrypted credential file used by the AWS SDK for .NET and AWS Toolkit for Visual Studio first. If the profile is not found then the cmdlet will search in the ini-format credential file at the default location: (user's home directory)\.aws\credentials.If this parameter is specified then this cmdlet will only search the ini-format credential file at the location given.As the current folder can vary in a shell or during script execution it is advised that you use specify a fully qualified path instead of a relative path.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAWSProfilesLocation, ProfilesLocation
-ProfileName <String>
The user-defined name of an AWS credentials or SAML-based role profile containing credential information. The profile is expected to be found in the secure credential file shared with the AWS SDK for .NET and AWS Toolkit for Visual Studio. You can also specify the name of a profile stored in the .ini-format credential file used with the AWS CLI and other AWS SDKs.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesStoredCredentials, AWSProfileName
-Region <Object>
The system name of an AWS region or an AWSRegion instance. This governs the endpoint that will be used when calling service operations. Note that the AWS resources referenced in a call are usually region-specific.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesRegionToCall
-SecretKey <String>
The AWS secret key for the user account. This can be a temporary secret key if the corresponding session token is supplied to the -SessionToken parameter.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesSK, SecretAccessKey
-SessionToken <String>
The session token if the access and secret keys are temporary session-based credentials.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesST

Outputs

When deleting a single object.
When deleting multiple objects.

Examples

Example 1

Remove-S3Object -BucketName amzn-s3-demo-bucket -Key sample.txt
This command removes the object "sample.txt" from bucket "test-files". You are prompted for confirmation before the command executes; to suppress the prompt use the -Force switch.

Example 2

Remove-S3Object -BucketName amzn-s3-demo-bucket -Key sample.txt -VersionId HLbxnx6V9omT6AQYVpks8mmFKQcejpqt
This command removes the specified version of object "sample.txt" from bucket "test-files", assuming the bucket has been configured to enable object versions.

Example 3

Remove-S3Object -BucketName amzn-s3-demo-bucket -KeyCollection @( "sample1.txt", "sample2.txt", "sample3.txt" )
This command removes objects "sample1.txt", "sample2.txt" and "sample3.txt" from bucket "test-files" as a single batch operation. The service response will list all keys processed, regardless of the success or error status of the deletion. To obtain only errors for keys that were not able to be processed by the service add the -ReportErrorsOnly parameter (this parameter can also be specified with the alias -Quiet.

Example 4

Remove-S3Object -bucketname "amzn-s3-demo-bucket" -KeyCollection (Get-S3Object "test-files" -KeyPrefix "prefix/subprefix" | select -ExpandProperty Key)
This example uses an inline expression with the -KeyCollection parameter to obtain the keys of the objects to delete. Get-S3Object returns a collection of Amazon.S3.Model.S3Object instances, each of which has a Key member of type string identifying the object.

Example 5

Get-S3Object -BucketName "amzn-s3-demo-bucket" -KeyPrefix "prefix/subprefix" | Remove-S3Object -Force
This example obtains all objects that have a key prefix "prefix/subprefix" in the bucket and deletes them. Note that the incoming objects are processed one at a time. For large collections consider passing the collection to the cmdlet's -InputObject (alias -S3ObjectCollection) parameter to enable the deletion to occur as a batch with a single call to the service.

Example 6

(Get-S3Version -BucketName "amzn-s3-demo-bucket").Versions | Where {$_.IsDeleteMarker -eq "True"} | Remove-S3Object -Force
This example pipes a collection of Amazon.S3.Model.S3ObjectVersion instances that represent delete markers to the cmdlet for deletion. Note that the incoming objects are processed one at a time. For large collections consider passing the collection to the cmdlet's -InputObject (alias -S3ObjectCollection) parameter to enable the deletion to occur as a batch with a single call to the service.

Example 7

$keyVersions = @()
$markers = (Get-S3Version -BucketName $BucketName).Versions | Where {$_.IsDeleteMarker -eq "True"}
foreach ($marker in $markers) { $keyVersions += @{ Key = $marker.Key; VersionId = $marker.VersionId } }
Remove-S3Object -BucketName $BucketName -KeyAndVersionCollection $keyVersions -Force
This script shows how to perform a batch delete of a set of objects (in this case delete markers) by constructing an array of objects to be used with the -KeyAndVersionCollection parameter.

Supported Version

AWS Tools for PowerShell: 2.x.y.z