Add-Type load assembly from network UNC share error 0x80131515

前端 未结 3 816
后悔当初
后悔当初 2020-12-06 19:17

When you want to add an assembly from a network UNC share using the command:

$scriptPath = Split-Path ($MyInvocation.MyCommand.Path)
Add-Type -path \"$script         


        
相关标签:
3条回答
  • 2020-12-06 20:03

    The key is to allow for loading an assembly from a network path for a PowerShell executable. It can be done by creating the two files

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe.config

    and paste this code:

    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration>
       <runtime>
          <loadFromRemoteSources enabled="true"/>
       </runtime>
    </configuration>
    
    0 讨论(0)
  • 2020-12-06 20:05

    Instead of Add-Type you could:

    [System.Reflection.Assembly]::UnsafeLoadFrom('\\uncpath\driver.dll')
    

    It'll ignore some security settings and load the library but it's, well, unsafe ;).

    0 讨论(0)
  • 2020-12-06 20:08

    Re: ALIENQuake's. I've added your fix to a PS script to install the files in the correct locations.

    $PSPaths = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config','C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe.config'
    $XMLCode = @"
    <?xml version="1.0" encoding="utf-8" ?> 
    <configuration>
       <runtime>
             <loadFromRemoteSources enabled="true"/>
        </runtime>
    </configuration>
    "@
    foreach($PSConfigFile in $PSPaths) {
        $xmlcode | Out-File -FilePath $PSConfigFile -Encoding utf8 
    }
    
    0 讨论(0)
提交回复
热议问题