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

Invokes the DeleteObjects operation against Amazon S3.

Syntax

WithKey (Default)

Remove-S3Object
-BucketName <String>
-Key <String>
-VersionId <String>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>

WithKeyVersionCollection

Remove-S3Object
-BucketName <String>
-KeyAndVersionCollection <KeyVersion[]>
-ReportErrorsOnly <SwitchParameter>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>

WithKeyCollection

Remove-S3Object
-BucketName <String>
-KeyCollection <String[]>
-ReportErrorsOnly <SwitchParameter>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>

WithS3ObjectCollection

Remove-S3Object
-InputObject <S3Object[]>
-ReportErrorsOnly <SwitchParameter>
-SerialNumber <String>
-AuthenticationValue <String>
-Force <SwitchParameter>
-UseAccelerateEndpoint <SwitchParameter>
-UseDualstackEndpoint <SwitchParameter>

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 with a single call to the service specify the collection as the value of the -InputObject parameter. The -KeyCollection and -KeyAndVersionCollection parameters automatically process as a batch and make a single call to the service to delete all of the 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?False
-BucketName <String>
The name of the bucket containing the object(s) to be deleted.
Required?True
Position?1
Accept pipeline input?True (ByValue, ByPropertyName)
-Force <SwitchParameter>
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?False
-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, )
-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?False
-KeyCollection <String[]>
Collection of key names describing the S3 objects to be deleted.
Required?True
Position?Named
Accept pipeline input?False
-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?False
-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?False
-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?False
-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?False
-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? False
-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? False
-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. Note that the encrypted credential file is not supported on all platforms. It will be skipped when searching for profiles on Windows Nano Server, Mac, and Linux platforms.

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? False
-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? False
-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? False
-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? False
-SessionToken <String>
The session token if the access and secret keys are temporary session-based credentials.
Required? False
Position? Named
Accept pipeline input? False
-Region <String>
The system name of the AWS region in which the operation should be invoked. For example, us-east-1, eu-west-1 etc.
Required? False
Position? Named
Accept pipeline input? False
-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? False

Inputs

You can pipe a String object to this cmdlet for the BucketName parameter.
You can pipe a S3Object[] object to this cmdlet for the InputObject parameter.

Outputs

When deleting a single object.
When deleting multiple objects.

Examples

Example 1

PS C:\>Remove-InputObject -BucketName test-files -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

PS C:\>Remove-InputObject -BucketName test-files -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

PS C:\>Remove-InputObject -BucketName test-files -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

PS C:\>Remove-S3Object -bucketname "test-files" -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

PS C:\>Get-InputObject -BucketName "test-files" -KeyPrefix "prefix/subprefix" | Remove-InputObject -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

PS C:\>(Get-S3Version -BucketName "test-files").Versions | Where {$_.IsDeleteMarker -eq "True"} | Remove-InputObject -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

PS C:\> $keyVersions = @()
PS C:\> $markers = (Get-S3Version -BucketName $BucketName).Versions | Where {$_.IsDeleteMarker -eq "True"}
PS C:\> foreach ($marker in $markers) { $keyVersions += @{ Key = $marker.Key; VersionId = $marker.VersionId } }
PS C:\> Remove-InputObject -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