I am trying to script the execution of an installer on remote web servers. The installer in question is also a Windows Service that hosts NServiceBus. If RDP'd into the server, the application is installed by the following command:
&"$theInstaller" /install /serviceName:TheServiceName
The installer prints output about its progress registering the service and connecting to the database to stdout, among other things.
This works fine from an RDP session, but when I execute it remotely via PS, I get a you-can't-do-this-over-the-network message if I execute it directly or via Invoke-Command -computername $theRemoteServer:
System.IO.FileLoadException: Could not load file or assembly 'file://\\theRemoteServer\c$
\thePath\AutoMapper.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) --- System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
(Note: I added an additional "\" to the path in the first line in order to get it to show up correctly in the preview on this site.)
This, and other DLLs, are loaded by the service, and the service's execution context cannot, apparently, be remotified.
I have also tried using Invoke-WmiMethod, which does something, but it's not clear what, and the output from the installer is lost:
Invoke-WMIMethod win32_process create '"$theInstaller" /install /serviceName:TheServiceName' -ComputerName $server (with and without cmd.exe /k before the intaller reference):
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId :
ReturnValue : 9
How does one remotely execute such an EXE and capture the output?
Thanks!