Share via


Get-SqlBackupHistory

Gets backup information about databases and returns SMO BackupSet objects for each Backup record found based on the parameters specified to this cmdlet.

Syntax

ByPath (Default)

Get-SqlBackupHistory
    [[-Path] <String[]>]
    [-Since <SinceType>]
    [-StartTime <DateTime>]
    [-EndTime <DateTime>]
    [-BackupType <BackupSetType>]
    [-IncludeSnapshotBackups]
    [-TimeSpan <TimeSpan>]
    [-IgnoreProviderContext]
    [-SuppressProviderContextWarning]
    [-AccessToken <PSObject>]
    [-TrustServerCertificate]
    [-HostNameInCertificate <String>]
    [-Encrypt <String>]
    [-DatabaseName <System.Collections.Generic.List`1[System.String]>]
    [<CommonParameters>]

ByName

Get-SqlBackupHistory
    [[-ServerInstance] <String[]>]
    [-Since <SinceType>]
    [-StartTime <DateTime>]
    [-EndTime <DateTime>]
    [-BackupType <BackupSetType>]
    [-IncludeSnapshotBackups]
    [-TimeSpan <TimeSpan>]
    [-IgnoreProviderContext]
    [-SuppressProviderContextWarning]
    [-Credential <PSCredential>]
    [-ConnectionTimeout <Int32>]
    [-AccessToken <PSObject>]
    [-TrustServerCertificate]
    [-HostNameInCertificate <String>]
    [-Encrypt <String>]
    [-DatabaseName <System.Collections.Generic.List`1[System.String]>]
    [<CommonParameters>]

ByObject

Get-SqlBackupHistory
    [-InputObject] <Server[]>
    [-Since <SinceType>]
    [-StartTime <DateTime>]
    [-EndTime <DateTime>]
    [-BackupType <BackupSetType>]
    [-IncludeSnapshotBackups]
    [-TimeSpan <TimeSpan>]
    [-IgnoreProviderContext]
    [-SuppressProviderContextWarning]
    [-AccessToken <PSObject>]
    [-TrustServerCertificate]
    [-HostNameInCertificate <String>]
    [-Encrypt <String>]
    [-DatabaseName <System.Collections.Generic.List`1[System.String]>]
    [<CommonParameters>]

Description

This cmdlet searches the server instance and gets the backup records as SMO BackupSet objects for all the records found matching the specified parameters.

Examples

Example 1

PS C:\> Get-SqlBackupHistory -ServerInstance test-server -DatabaseName AdventureWorks2014

Name                                     Type               Backup Start Date         Backup Finish Date
----                                     ----               -----------------         ------------------
AdventureWorks2014-Full Database Backup  Database           2/21/2017 7:52:39 PM      2/21/2017 7:52:40 PM
AdventureWorks2014-Full Database Backup  Database           3/20/2017 2:41:39 PM      3/20/2017 2:41:39 PM
AdventureWorks2014-Full-2017-07-24T22:22 Database           7/24/2017 3:23:11 PM      7/24/2017 3:23:11 PM

This example gets records for all backup types for AdventureWorks2014 database on test-server SQL instance.

Parameters

-AccessToken

The access token used to authenticate to SQL Server, as an alternative to user/password or Windows Authentication.

This can be used, for example, to connect to SQL Azure DB and SQL Azure Managed Instance using a Service Principal or a Managed Identity.

The parameter to use can be either a string representing the token or a PSAccessToken object as returned by running Get-AzAccessToken -ResourceUrl https://database.windows.net.

This parameter is new in v22 of the module.

Parameter properties

Type:PSObject
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-BackupType

The type of backup to filter on. If not specified then gets all backup types. Accepted values are defined below.

Parameter properties

Type:BackupSetType
Default value:None
Accepted values:Database, Differential, Incremental, Log, FileOrFileGroup, FileOrFileGroupDifferential
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ConnectionTimeout

The time to wait in seconds for a connection to be established and the dynamically generated -DatabaseName parameter to be populated.

Parameter properties

Type:Int32
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ByName
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Credential

The PSCredential object whose username and password fields are used to connect to the SQL instance.

Parameter properties

Type:PSCredential
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ByName
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-DatabaseName

The names of the databases whose backup records are to be retrieved. This is a dynamically populated field and so provides auto-complete suggestions on database names.

Parameter properties

Type:

System.Collections.Generic.List`1[System.String]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Encrypt

The encryption type to use when connecting to SQL Server.

This value maps to the Encrypt property SqlConnectionEncryptOption on the SqlConnection object of the Microsoft.Data.SqlClient driver.

In v22 of the module, the default is Optional (for compatibility with v21). In v23+ of the module, the default value will be 'Mandatory', which may create a breaking change for existing scripts.

This parameter is new in v22 of the module.

Parameter properties

Type:String
Default value:None
Accepted values:Mandatory, Optional, Strict
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-EndTime

The time before which all backup records to be retrieved should have completed.

Parameter properties

Type:DateTime
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-HostNameInCertificate

The host name to be used in validating the SQL Server TLS/SSL certificate. You must pass this parameter if your SQL Server instance is enabled for Force Encryption and you want to connect to an instance using hostname/shortname. If this parameter is omitted then passing the Fully Qualified Domain Name (FQDN) to -ServerInstance is necessary to connect to a SQL Server instance enabled for Force Encryption.

This parameter is new in v22 of the module.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-IgnoreProviderContext

Indicates that this cmdlet does not use the current context to override the values of the ServerInstance, DatabaseName parameters. If you do not specify this parameter, the cmdlet ignores the values of these parameters, if possible, in favor of the context in which you run the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-IncludeSnapshotBackups

This switch will make the cmdlet obtain records for snapshot backups as well. By default such backups are not retrieved.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-InputObject

Specifies SMO Server objects to get the backup records for.

Parameter properties

Type:

Server[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ByObject
Position:1
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-Path

Specifies the SQL provider path to either a server instance or a database for this cmdlet to use to obtain BackupSets for. If not specified uses the current working location.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ByPath
Position:1
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ServerInstance

The name of the server instances which this cmdlet will target.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ByName
Position:1
Mandatory:False
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-Since

Specifies an abbreviation that you can instead of the StartTime parameter.

It can be specified with the EndTime parameter.

You cannot use the StartTime parameter, if you use this parameter.

The acceptable values for this parameter are:

  • Midnight (gets all the job history information generated after midnight)
  • Yesterday (gets all the job history information generated in the last 24 hours)
  • LastWeek (gets all the job history information generated in the last week)
  • LastMonth (gets all the job history information generated in the last month)

Parameter properties

Type:SinceType
Default value:None
Accepted values:Midnight, Yesterday, LastWeek, LastMonth
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-StartTime

Gets the backup records which started after this specified time.

Parameter properties

Type:DateTime
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-SuppressProviderContextWarning

Suppresses the warning when the cmdlet is using the provider context.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-TimeSpan

If specified, it causes the cmdlet to filter records generated more than 'Timespan' ago.

Parameter properties

Type:TimeSpan
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-TrustServerCertificate

Indicates whether the channel will be encrypted while bypassing walking the certificate chain to validate trust.

In v22 of the module, the default is $true (for compatibility with v21). In v23+ of the module, the default value will be '$false', which may create a breaking change for existing scripts.

This parameter is new in v22 of the module.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

System.String

Microsoft.SqlServer.Management.Smo.Server

Outputs

System.Object