Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [string] $backupfile="C:\DBFiles\Foo.bak"
- [string] $sqlinstance = 'localhost'
- #load assemblies
- [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
- [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
- #instantiate SMO server
- $smosrv = new-object ('Microsoft.SqlServer.Management.Smo.Server') $sqlinstance
- #if file exists, provide information
- if(Test-Path $backupfile){
- $file = gci $backupfile
- $restore=new-object("Microsoft.SqlServer.Management.Smo.Restore")
- $restore.Devices.AddDevice($file.FullName, "File")
- $restore.ReadBackupHeader($smosrv) | ft DatabaseName,DatabaseVersion,Compressed
- }
- else{"File does not exist!"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement