I've created a central repository for Powershell modules, but I'm having trouble loading one in particular. The NTFSSecurity module is failing to import with the following message.
PS Z:\> Import-Module NTFSSecurity
Add-Type : Could not load file or assembly 'file://\\fs\PowerShellModules\NTFSSecurity\Security2.dll' or one of its
dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At \\fs\PowerShellModules\NTFSSecurity\NTFSSecurity.Init.ps1:141 char:1
+ Add-Type -Path $PSScriptRoot\Security2.dll
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Could not load file or assembly 'file://\\fs\PowerShellModules\NTFSSecurity\PrivilegeControl.dll' or one
of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At \\fs\PowerShellModules\NTFSSecurity\NTFSSecurity.Init.ps1:142 char:1
+ Add-Type -Path $PSScriptRoot\PrivilegeControl.dll -ReferencedAssemblies $PSScrip ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Could not load file or assembly 'file://\\fs\PowerShellModules\NTFSSecurity\ProcessPrivileges.dll' or one
of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At \\fs\PowerShellModules\NTFSSecurity\NTFSSecurity.Init.ps1:143 char:1
+ Add-Type -Path $PSScriptRoot\ProcessPrivileges.dll
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
Types added
NTFSSecurity Module loaded
Import-Module : Unable to find type [Security2.IdentityReference2]: make sure that the assembly containing this type
is loaded.
At line:1 char:1
+ Import-Module NTFSSecurity
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Security2.IdentityReference2:TypeName) [Import-Module], RuntimeExcept
ion
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
I'm running Windows Managment Foundation 3.0 Beta, which includes PowerShell 3.0. I have a feeling that the new security measures introduced in .NET 4.0 are playing a part in this, but running Powershell.exe
with the -version 2.0
switch doesn't fix anything either. I have modified my powershell.exe.config files in both the system32 and SysWOW64 folders to the following.
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<loadfromremotesources enabled="true"/>
</runtime>
</configuration>
The files are not "blocked", I've checked each one individually (as well as run Unblock-File
on the directory). Permissions from the server end are fine, I've verified that I have access to everything. What have I not checked?
It might be a corrupt file/bad download.
I was receiving the same error when trying to load the module from one of my scripts. I went and re-downloaded the newer v2.3 and extracted it into my Powershell Modules folder (C:\windows\system32\WindowsPowershell\v1.0\Modules\NTFSSecurity).
This solved my problem.
Rather than load the module directly from a share, I tend to have a function that copies it locally (this can be adjusted to look for newer versions as well). I suppose this could be written in-line, but I made it a function as part of my 'common modules' that I load.
Function Import-NTFSModule {
$NTModule = 'C:\Windows\System32\WindowsPowershell\v1.0\Modules\NTFSSecurity'
$NTSource = '\\servername.fqdn\sharename\Modules\NTFSSecurity'
If (!(Get-Module -Name NTFSSecurity)) {
If (!(Test-Path -Path $NTModule) -and (Test-Path $NTSource)) { Copy-Item $NTSource -Destination "$NTModule\" -Recurse -Force }
}
}
By default, the .ZIP file you download is blocked from being executed. Right-click it and choose "Unblock" before you unpack it, and the files beneath will be unblocked as well.
Sorry that when I originally posted, I didn't see that you said you had unblocked it. I only got the error (identical error code) while the files were in a blocked state.
Run the Import-Module NTFSSecurity from Windows Powershell (not the ISE)
User contributions licensed under CC BY-SA 3.0