commands

^

Remove-DbaDbSnapshot

Author Simone Bizzotto (@niphold)
Availability Windows, Linux, macOS

 

Synopsis

Removes database snapshots

Description

Removes (drops) database snapshots from the server

Syntax

Remove-DbaDbSnapshot
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-ExcludeDatabase] <String[]>]
    [[-Snapshot] <String[]>]
    [[-InputObject] <Database[]>]
    [-AllSnapshots]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Remove-DbaDbSnapshot -SqlInstance sql2014 -Snapshot HR_snap_20161201, HR_snap_20161101

Removes database snapshots named HR_snap_20161201 and HR_snap_20161101

Example: 2
PS C:\> Remove-DbaDbSnapshot -SqlInstance sql2014 -Database HR, Accounting

Removes all database snapshots having HR and Accounting as base dbs

Example: 3
PS C:\> Get-DbaDbSnapshot -SqlInstance sql2014 -Database HR, Accounting | Remove-DbaDbSnapshot

Removes all database snapshots having HR and Accounting as base dbs

Example: 4
PS C:\> Remove-DbaDbSnapshot -SqlInstance sql2014 -Snapshot HR_snapshot, Accounting_snapshot

Removes HR_snapshot and Accounting_snapshot

Example: 5
PS C:\> Get-DbaDbSnapshot -SqlInstance sql2016 | Where-Object SnapshotOf -like '*dumpsterfire*' | Remove-DbaDbSnapshot

Removes all snapshots associated with databases that have dumpsterfire in the name

Example: 6
PS C:\> Get-DbaDbSnapshot -SqlInstance sql2016 | Out-GridView -PassThru | Remove-DbaDbSnapshot

Allows the selection of snapshots on sql2016 to remove

Example: 7
PS C:\> Remove-DbaDbSnapshot -SqlInstance sql2014 -AllSnapshots

Removes all database snapshots from sql2014

Example: 8
PS C:\> Remove-DbaDbSnapshot -SqlInstance sql2014 -AllSnapshots -Confirm

Removes all database snapshots from sql2014 and prompts for each database

Optional Parameters

-SqlInstance

The target SQL Server instance or instances

Alias
Required False
Pipeline false
Default Value
-SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported. For MFA support, please use Connect-DbaInstance.

Alias
Required False
Pipeline false
Default Value
-Database

Removes snapshots for only this specific base db

Alias
Required False
Pipeline false
Default Value
-ExcludeDatabase

Removes snapshots excluding this specific base dbs

Alias
Required False
Pipeline false
Default Value
-Snapshot

Restores databases from snapshot with this name only

Alias
Required False
Pipeline false
Default Value
-InputObject

Enables input from Get-DbaDbSnapshot

Alias
Required False
Pipeline true (ByValue)
Default Value
-AllSnapshots

Specifies that you want to remove all snapshots from the server

Alias
Required False
Pipeline false
Default Value False
-Force

Will forcibly kill all running queries that prevent the drop process.

Alias
Required False
Pipeline false
Default Value False
-EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

Shows what would happen if the command were to run

Alias wi
Required False
Pipeline false
Default Value
-Confirm

Prompts for confirmation of every step.

Alias cf
Required False
Pipeline false
Default Value

 

Want to see the source code for this command? Check out Remove-DbaDbSnapshot on GitHub.
Want to see the Bill Of Health for this command? Check out Remove-DbaDbSnapshot.