Sample Powershell v2 script using AlphaVSS

Jan 3, 2010 at 8:04 PM

I haven't tested this code fully (on all platforms, etc.), and will attach a much more complete example shortly (with comments, and a few tips).

But for now, this is a sample Powershell v2 script using AlphaVSS that definitely works on Windows 7 x86. 

HTH, comments are welcome!

-Dave

	Add-Type -path "AlphaVSS.Common.dll"
	$oVSSImpl = [Alphaleonis.Win32.Vss.VssUtils]::LoadImplementation()
	
	$oVSS = $oVSSImpl.CreateVssBackupComponents()
	$oVSS.GetType().GetMethod("InitializeForBackup").Invoke($oVSS, @($Null))

	$oVSS.SetContext([Alphaleonis.Win32.Vss.VssSnapshotContext]::Backup)
	$oVSS.SetBackupState($False, $True, [Alphaleonis.Win32.Vss.VssBackupType]::Copy, $False)

	$async = $oVSS.GatherWriterMetadata(); $async.Wait()

	$SnapShotSetGUID = $oVSS.StartSnapshotSet()	
	$SnapshotGUID    = $oVSS.AddToSnapshotSet("C:\")

	$async = $oVSS.PrepareForBackup();     $async.Wait()	
	$async = $oVSS.DoSnapshotSet();        $async.Wait()

	$params = @($SnapshotGUID, "\", [Alphaleonis.Win32.Vss.VssVolumeSnapshotAttributes]::ExposedRemotely, $Null)
	$drive  = $oVSS.GetType().GetMethod("ExposeSnapshot").Invoke($oVSS, $params)
	
###	This is where you could use the shadow copy, say from \\localhost\share{...}

	$async = $oVSS.BackupComplete();       $async.Wait()

	$count = $oVSS.DeleteSnapshotSet($SnapshotSetGUID, $False)
	$oVSS.Dispose()