Page 1 of 1

Project .exe Module .dll Could not load file assembly

Posted: Mon Oct 01, 2018 10:01 am
by Genx13
Using Powershell Studio 2017
I have a Script that works normally as a .ps1 that uses the NTFSSecurity Module (https://gallery.technet.microsoft.com/s ... 85#content). If I Build the same files into a .exe the module is imported successfully, but when it comes to running the cmd's associated with the module I get an error.
Add-NTFSAccess : Could not load file or assembly 'AlphaFS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=4d31a58f7d7ad5c9' or one of its dependencies. The system cannot find the file specified.
I understand this is saying a file can not be found but it runs normally as a script(.ps1). In Powershell Studio The Module is listed and checked in my cache.
Here Is the command

Code: Select all

Import-module NTFSSecurity
$HomeDirectory = SomeDirectory
$SAM = SomeUserName
Get-Item $HomeDirectory | Add-NTFSAccess -Account $SAM -AccessRights FullControl

Re: Project .exe Module .dll Could not load file assembly

Posted: Mon Oct 01, 2018 10:16 am
by jvierra
Files are not included in an EXE. The module must exist and be in the module path on the target system.

You should start by upgrading to the current version of the module:

Install-Module NTFSSecurity

This will upgrade the module.

Note that you must remove the existing "Gallery" module first by deleting its folder. The old module is not compatible with the PowerShell Gallery version

Re: Project .exe Module .dll Could not load file assembly

Posted: Mon Oct 01, 2018 10:48 am
by Genx13
I ran the

Code: Select all

Install-Module NTFSSecurity
Cleared and rebuilt the module cache. Re-Built .exe and Im getting the same error.
Add-NTFSAccess : Could not load file or assembly 'AlphaFS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=4d31a58f7d7ad5c9' or one of its dependencies.
The system cannot find the file specified.
This installed the version 4.2.4 of the module

Re: Project .exe Module .dll Could not load file assembly

Posted: Mon Oct 01, 2018 11:01 am
by jvierra
Works fine for me. Are you trying to run this from an packaged file (EXE)?

Re: Project .exe Module .dll Could not load file assembly

Posted: Mon Oct 01, 2018 11:09 am
by Genx13
Yes
Im using Powershell Studio to build the .exe, It does work if I export it as a .ps1 file.

Re: Project .exe Module .dll Could not load file assembly

Posted: Mon Oct 01, 2018 11:18 am
by jvierra
I can build an EXE with no issues. Since this is a PSS 2017 issue I recommend posting in the REgister Customers forum for PSS and let the Sapien techs look at this. I do not have an installed version of 2017 so I cannot test with that version. Sapien has your version available.

The issue appears to be an issue with the build engine.

Be sure you are building with the correct host.

Re: Project .exe Module .dll Could not load file assembly

Posted: Tue Oct 02, 2018 9:28 am
by Genx13
So here is an update I did get it to work after some more trial and error, first the

Code: Select all

Install-Module NTFSSecurity
Was the right track. I didn't realize the module was 64bit (which could have been because I was running 64bit PS) so it was put in the SysWOW64 Module Directory. After I figured that out I did some more googleing because I was still getting the error. I found the link below which explains Importing the AlphaFS.dll as a module.

https://github.com/alphaleonis/AlphaFS/wiki/PowerShell

The download link from there leads to the page below, where you can download a zip file of multiple AlphaFS versions (Per my Error Message I needed 2.2.0).

https://github.com/alphaleonis/AlphaFS/releases

I unzipped it placed it in the folder with the .exe and added the commands below in that order

Code: Select all

Import-Module .\AlphaFS.2.2.0.0\Lib\Net40\AlphaFS.dll
Import-Module NTFSSecurity
And everything ran correctly. Thanks to everyone for their help.