# Executing program on remote computer help

**URL:** <https://forums.powershell.org/t/executing-program-on-remote-computer-help/2066>\
**Category:** PowerShell Help\
**Created:** [November 13, 2013, 7:06am UTC](https://forums.powershell.org/t/executing-program-on-remote-computer-help/2066 "2013-11-13T07:06:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![derek-engel](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@derek-engel](https://forums.powershell.org/u/derek-engel)\
**Post date:** [November 13, 2013, 7:06am UTC](https://forums.powershell.org/t/executing-program-on-remote-computer-help/2066/1 "2013-11-13T07:06:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 13, 2013, 7:15am UTC](https://forums.powershell.org/t/executing-program-on-remote-computer-help/2066/2 "2013-11-13T07:15:57Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![derek-engel](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@derek-engel](https://forums.powershell.org/u/derek-engel)\
**Post date:** [November 13, 2013, 7:28am UTC](https://forums.powershell.org/t/executing-program-on-remote-computer-help/2066/3 "2013-11-13T07:28:14Z")

</div>

Thanks Dave that did the trick!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:56pm UTC](https://forums.powershell.org/t/executing-program-on-remote-computer-help/2066/4 "2024-05-16T20:56:52Z")

</div>


