Search code examples
powershellgac

Installing assembly in GACUTIL with Invoke-Command in PowerShell (no permissions)


I try to run a PowerShell-script that invokes a command. In that command I want to write a assembly to the GAC.

This is the code:

invoke-command -computername COMPUTERNAME -scriptblock { 
$gacUtil = "${Env:ProgramFiles(x86)}\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe"; 
& $gacutil '/nologo' '/if' '\\fileserver\..\Assembly.dll' 
} 

PowerShell then returns this error:

Failure adding assembly to the cache: Administrator permissions are needed to use the selected options. Use an administrator command prompt to complete these tasks.

After some googling, I added a -Credential parameter to the invoke-command (with the Administrator-Credentials), but that still doesn't work.

Any ideas?


Solution

  • The error came from the assembly ('\fileserver..\Assembly.dll') to put in the GAC, not the gacutil.exe.

    A good alternative posted by Christian: mmmh, a little googling give me only this approach to remote install assembly in GAC