Executing program on remote computer help

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

  • Author
    Posts
  • #11441

    Lery
    Participant

    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
    Moderator

    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

    Lery
    Participant

    Thanks Dave that did the trick!

You must be logged in to reply to this topic.