powershell script to get database list with no FULL backup or FULL backup older than 7 days in sql server

M Navaneeswara Reddy 1 Reputation point
2021-09-28T14:08:04.02+00:00

Please provide powershell script to get database list with no FULL backup or FULL backup older than 7 days in sql server

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,793 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Ronen Ariely 15,096 Reputation points
    2021-09-28T22:02:31.07+00:00

    Hi,

    You are correct and I had required T-SQL query , but not in PowerShell . Please help me if you have any PowerShell script to get details

    According to your new information in the comment you know hw to get the information via queries.

    This mean that you only need to learn how to execute queries from PowerShell.

    This is done using the command Invoke-Sqlcmd

    You can get more information in the relevant documentation here:

    https://learn.microsoft.com/en-us/powershell/module/sqlserver/invoke-sqlcmd?view=sqlserver-ps

    Note! This command is a utility which is part of the SqlServer Module. It is not installed by default. Therefore, you might encounter the following error message:

    The term 'Invoke-Sqlcmd' is not recognized as the name of a cmdlet, function, script file, or operable program.

    You can install the module using the command Install-Module sqlserver

    0 comments No comments

  2. Seeya Xi-MSFT 16,441 Reputation points
    2021-09-29T06:01:02.3+00:00

    Hi @NavaneeshwarReddy-8681,

    This link may could give you some greater ideas about sql scripts:
    https://www.mssqltips.com/sqlservertip/1601/script-to-retrieve-sql-server-database-backup-history-and-no-backups/

    How to execute SQL Script using windows powershell

    Yes. You can use invoke-sqlcmd.
    Here is a similar thread: https://social.msdn.microsoft.com/Forums/en-US/b811c1b7-1fda-4027-ab97-9ecb1fabff36/how-to-execute-sql-script-using-windows-powershellusing-invokesqlcmd-or-any-if?forum=sqlsecurity

    Best regards,
    Seeya


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Anthony Axlen 1 Reputation point
    2021-09-30T08:55:33.51+00:00

    Hello,

    I agree with the previous responses, that usage of Invoke-Sqlcmd cmdlet (part of SQLPS module) helps you with direct SQL query (with -Query param) or query saved in file (with -InputFile param).

    The second option I would recommend is DBAtools PS module with Get-DBABackupHistory function - description with examples of usage are well presented on docs.dbatools.io.

    Thank you.

    0 comments No comments