I am trying to run a script that queries the last full backup file for a specific database. Invoke line formated for ease of reading.
# Script is ran on the SQL server (not remotely)
# Instance is called sql-instance
# database is called sql-data
import-module SQLPS -disableNameChecking
$instanceName = "$($env:computername)\sql-instance"
$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
$lastBackupFile = Invoke-Sqlcmd -Query "
SELECT TOP 1 msdb.dbo.backupmediafamily.physical_device_name
INNER JOIN msdb.dbo.backupset ON msdb.dbo.backupmediafamily.media_set_id = msdb.dbo.backupset.media_set_id
WHERE msdb..backupset.type = 'D' and msdb.dbo.backupset.database_name = 'sql-data'
ORDER BY msdb.dbo.backupset.backup_finish_date desc"
The result I get with this is in a table format:
C:\Program Files\Microsoft SQL Server\MSSQL11.SIMS2012\MSQL\Backup\full_sql-data_20121101.bak
Is there any way to just get the result and not the heading stuff?
I need just the path and filename for using elsewhere in the script.
I tried searching around but only found articles that give the table format and I don't know enouth to trim this down with confidence.
Thanks in advance