Executing program on remote computer help

This topic contains 2 replies, has 2 voices, and was last updated by  Lery 4 years, 7 months ago.

  • Author
  • #11441


    Hello and thank you for your time. Here is what I'm trying to do and the requirements behind it.

    PowerShell 2.0

    Must execute on remote computer

    Script so far:

    $RemoteDll = "c:\program files (x86)\test\location\application.dll"
    invoke-command -computername 'test-pc01' -ScriptBlock { & 'regsvr32' $RemoteDll}

    The above command does not work to register application.dll.

    In addition to registering the DLL I need to unregister it. Therefore, I need to use the /u switch along with the /s switch for silent.

    Where am I going wrong?

  • #11442

    Dave Wyatt

    The script block you pass to Invoke-Command does not inherit any variables from your local scope. In this case, $RemoteDll is an uninitialized (null) value when the command runs on the remote computer. You need to pass the value as an argument, and write the script block to accept positional parameters (either by name, or in the automatic $args array). For example:

    $RemoteDll = "c:\program files (x86)\test\location\application.dll"
    invoke-command -computername 'test-pc01' -ScriptBlock { & 'regsvr32' $args[0] } -ArgumentList $RemoteDll
  • #11443


    Thanks Dave that did the trick!

You must be logged in to reply to this topic.