从UNCpath导入NTFSSecurity模块失败

我已经为Powershell模块创build了一个中央存储库,但是我特别在加载它时遇到了麻烦。 NTFSSecurity模块无法导入以下消息。

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 

我正在运行Windows Managment Foundation 3.0 Beta,其中包括PowerShell 3.0。 我有一种感觉,.NET 4.0中引入的新安全措施正在发挥作用,但运行带有-version 2.0开关的Powershell.exe并不能解决任何问题。 我已经将system32SysWOW64文件夹中的powershell.exe.config文件修改为以下内容。

 <?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> 

这些文件没有被“阻止”,我已经单独检查了每个Unblock-File (以及在目录上运行Unblock-File )。 从服务器端的权限是好的,我已经validation,我有权访问的一切。 我没有检查什么?

这可能是一个损坏的文件/不好的下载。

当我尝试从我的一个脚本加载模块时,我收到了同样的错误。 我去了,重新下载了较新的v2.3,并将其提取到我的Powershell Modules文件夹(C:\ windows \ system32 \ WindowsPowershell \ v1.0 \ Modules \ NTFSSecurity)。

这解决了我的问题。

而不是直接从共享中加载模块,我倾向于在本地复制它的function(这可以调整以寻找更新的版本)。 我想这可以写在线上,但我把它作为我加载的“通用模块”的一部分function。

 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 } } } 

默认情况下,您下载的.ZIP文件被阻止执行。 右键单击它并在解压缩之前select“解除阻止”,并且下面的文件也将被解除阻止。

对不起,当我最初发布,我没有看到你说你已经解除封锁。 我只有在文件处于阻塞状态时出现错误(相同的错误代码)。

Windows Powershell (而不是ISE )运行导入模块NTFSSecurity