Advertisement
mike_fal

PoSH - Check Backup Compression

Mar 26th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [string] $backupfile="C:\DBFiles\Foo.bak"
  2. [string] $sqlinstance = 'localhost'
  3.  
  4. #load assemblies
  5. [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
  6. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended") | Out-Null
  7.  
  8. #instantiate SMO server
  9. $smosrv = new-object ('Microsoft.SqlServer.Management.Smo.Server') $sqlinstance
  10.  
  11. #if file exists, provide information
  12. if(Test-Path $backupfile){
  13.     $file = gci $backupfile
  14.    
  15.     $restore=new-object("Microsoft.SqlServer.Management.Smo.Restore")
  16.     $restore.Devices.AddDevice($file.FullName, "File")
  17.    
  18.     $restore.ReadBackupHeader($smosrv) | ft DatabaseName,DatabaseVersion,Compressed
  19.     }
  20. else{"File does not exist!"}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement