Powershell 3.0 Support?

Mar 19, 2014 at 10:11 AM
Hi,
When i try to load the "AlphaFS.dll" file with Import-Module in Powershell 3.0 i get the following error:
"Import-Module : Could not load file or assembly 'file:///C:\Powershell\AlphaFS15\Release\AlphaFS.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)." Running Dot Net version: 4.0.30319.18063

Works with Powershell version 2 and Dot Net: 2.0.50727.5420
Developer
Mar 19, 2014 at 10:33 AM
Hi,

AlphaFS.dll should work without any problems.
Although personally I use a different implementation: [Reflection.Assembly]::LoadFile($Wase.Core.AlphaFs.Assembly)

Below is a PowerShell snippet which enables you to dynamically use either System.IO or AlphaFS:
...

#Region Initialize .NET System.IO
$Wase.Io = @{
    Directory = [IO.Directory]
    File      = [IO.File]
    Path      = [IO.Path]

    # AlphaFS only.
    Host = $Null

    DirectoryInfo = [IO.DirectoryInfo]
    FileInfo      = [IO.FileInfo]
}
#EndRegion Initialize .NET System.IO

#Region AlphaFS.dll
$Wase.Core.AlphaFs += @{ Assembly = (Join-Path -Path $Wase.Core.AppData -ChildPath 'AlphaFS.dll') }

If (Test-Path -Path $Wase.Core.AlphaFs.Assembly -PathType Leaf) {
    Try {
        $Wase.Core.AlphaFs.Dll     = [Reflection.Assembly]::LoadFile($Wase.Core.AlphaFs.Assembly)
        $Wase.Core.AlphaFs.Enabled = $True

        # Reassign IO classes to use AlphaFS.
        $Wase.Io = @{
            Directory = [Alphaleonis.Win32.Filesystem.Directory]
            File      = [Alphaleonis.Win32.Filesystem.File]
            Path      = [Alphaleonis.Win32.Filesystem.Path]

            # AlphaFS only.
            Host = [Alphaleonis.Win32.Network.Host]

            DirectoryInfo = [Alphaleonis.Win32.Filesystem.DirectoryInfo]
            FileInfo      = [Alphaleonis.Win32.Filesystem.FileInfo]
        }

        Write-WaseCoreLog -Message ('Initialized AlphaFS version: [{0}]' -f $Wase.Core.AlphaFs.Dll.GetName().Version) -Silent
    }
    Catch {
        $Wase.Core.AlphaFs.Enabled = $False  # Extra insurance; $Wase.Io might fail initializing fully.
        Write-WaseCoreLog -Level Excep -Silent
    }
}
#EndRegion AlphaFS.dll

...
And call it like: $Wase.Io.Directory::EnumerateDirectories($path)


Yomodo
Mar 19, 2014 at 10:58 AM
Thanks for the reply, but also found another thing that i miss. Do you have a recurse-switch?
I want to search for files in folderstructures that have longer than 260 characters and use the data for certain files.

To replace this: Dir $HomeDir -Recurse
Developer
Mar 19, 2014 at 11:03 AM
Edited Mar 23, 2014 at 3:54 PM
The snippet works?

You cannot use PowerShell switches, instead use the (.NET) method arguments:
$Wase.Io.Directory::EnumerateDirectories($path, "*", SearchOption.AllDirectories)

BUT, you'll need to download the latest development build, since the 1.5 version doesn't
contain the .NET 4 enum methods, if I remember correctly.

Yomodo
Nov 11, 2014 at 1:12 PM
Hi!

Thank you for your great work!
I even need this for PowerShell but .... what the hell contains or is $Wase ???????
Developer
Nov 11, 2014 at 1:14 PM
Thanks!

$WASE is a PowerShell HashTable.
Dec 16, 2014 at 6:36 PM
Hi i am also having issues getting this to work. I am running powershell 4.0

I've tried Import-Module -Name "C:\AlphaFS\AlphaFS.dll" but got the same error as mentioned above.
Import-Module : Could not load file or assembly 'file:///C:\AlphaFS\AlphaFS.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

I also tried the example that you mentioned but i think something is missing. I know you said that $Wase is a hashtable, but a hash table containing what?
If you could give a complete example as if you were creating a PowerShell script from scratch it would be really helpful.
Developer
Dec 17, 2014 at 9:59 AM
Edited Dec 17, 2014 at 5:20 PM
Hi!

Your syntax works fine for me.

Did you compile the dll yourself or is it a download?
If it's the latter, the .dll is probably blocked: right click on alphafs.dll en click "Unblock".

Minimal usage would be something like:
#Load AlphaFS, method 1
Import-Module -Name 'C:\AlphaFS\AlphaFS.dll'

#Load AlphaFS, method 2
[Reflection.Assembly]::LoadFile('C:\AlphaFS\AlphaFS.dll')

#Use AlphaFS function
[Alphaleonis.Win32.Filesystem.Directory]::EnumerateDirectories('C:\')

Try not to focus too hard on the $Wase variable, as it is just a place holder to easily access AlphaFS.
If you'd prefer a shorter reference, assign the full namespace to a PowerShell variable:
#Assign namespace to a variable
$AlphaFSDir = [Alphaleonis.Win32.Filesystem.Directory]
And then use the "short" form:
$AlphaFSDir::EnumerateDirectories('C:\')
Marked as answer by Yomodo on 12/31/2014 at 5:31 AM
Mar 18, 2015 at 12:34 PM
Hi,

I tried loading the new AlphaFS 2.0.1 using method 1 and 2 but it isn't working. I am getting the following error in powershell.
Import-Module : Could not load file or assembly 'file:///C:\AlphaFS\AlphaFS.dll' or one of its dependencies. Operation is not supported. (Exception from 
HRESULT: 0x80131515)
Au caractère Ligne:1 : 9
+         Import-Module -Name "C:\AlphaFS\AlphaFS.dll" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
Apr 15, 2015 at 11:11 AM
Edited Apr 15, 2015 at 11:12 AM
I second this. Whatever method I use to try to load the library, I get this:
PS D:\temp\AlphaFS> Import-Module -Name 'D:\Temp\AlphaFS\AlphaFS.dll' -verbose
VERBOSE: Loading module from path 'D:\Temp\AlphaFS\AlphaFS.dll'.
Import-Module : Could not load file or assembly 'file:///D:\Temp\AlphaFS\AlphaFS.dll' or one of its dependencies. The l
ocated assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
At line:1 char:1
+ Import-Module -Name 'D:\Temp\AlphaFS\AlphaFS.dll' -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
Windows 2008 R2 64
Powershell 4 / .NET 4.5.2.
Apr 15, 2015 at 1:26 PM
I ended up getting it to work. First you need to unblock the files or directory. I used the powershell unblock-file command, but for whatever reason i still wasn't able to use it until after i rebooted.