Unable to use AlphaVSS from powershell

May 19, 2011 at 6:04 AM
Edited May 19, 2011 at 6:09 AM

Hi,

I just saw alphaVSS library & think it's a great library to use VSS via .Net application.

I created a test app with the following code.  I set the platform as "Any CPU" & I am on Windows 2003 x86 machine. This works fine if I call it from any .Net app.

namespace

Common

{ 

public class Class1

 

 

{

 

public static string Test()

IVssImplementation vssImplementation = VssUtils.LoadImplementation();

{

 

string output = string.Empty;

using (IVssBackupComponents vss = vssImplementation.CreateVssBackupComponents())

{

 

 

 

 

 

vss.InitializeForBackup(

 

null);

 

vss.SetContext(

 

VssSnapshotContext.All);

 

 

foreach (VssSnapshotProperties props in vss.QuerySnapshots())

}

}

}

output += props.SnapshotId;

}

}

 

 

return output;

{

 

 

Console.WriteLine(props.SnapshotId);

Now  I am trying to call from powershell.

Here is my powershell script code.

----------------------------------------------------------------------------------------------------

add-type -Path .\AlphaVSS.Common.dll
add-type -Path .\AlphaVSS.Win2003.x86.dll
add-type -Path .\Common.dll

[Common.Class1]::Test()

----------------------------------------------------------------------------------------------------

I get following error.

Exception calling "Test" with "0" argument(s): "Could not load file or assembly
 'AlphaVSS.Win2003.x86, Version=1.0.9156.0, PublicKeyToken=3033cf2dbd31cad3' or
 one of its dependencies. The system cannot find the file specified."
At line:1 char:22
+ [Common.Class1]::Test <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I am not sure which assembly dependency it is looking for. Because I already add reference of 'AlphaVSS.Win2003.x86'. Any help would be much appreciated.

Atul Sureka

May 19, 2011 at 9:29 AM

I had a little play with it too and it does work.  Make sure the DLL is in the same folder as your PS script.


    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("D:\")

May 19, 2011 at 11:36 AM

Thanks a lot for quick response. Yes after putting the script into the same same directory works.

May 10, 2013 at 2:29 AM
having this error....dont know what to do.... Method 'DoSnapshotSet' in type 'Alphaleonis.Win32.Vss.VssBackupComponents' from assembly 'AlphaVSS.60.x86, Version=1.2.4000.3, Culture=neutral, PublicKeyToken=959d3993561034e3' does not have an implementation.