Executing program on remote computer help

Welcome Forums General PowerShell Q&A Executing program on remote computer help

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
5 years, 2 months ago.

  • Author
    Posts
  • #11441

    Participant
    Points: 1
    Rank: Member

    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

    Member
    Points: 0
    Rank: Member

    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

    Participant
    Points: 1
    Rank: Member

    Thanks Dave that did the trick!

The topic ‘Executing program on remote computer help’ is closed to new replies.