# How to run a PowerShell-Script remotely?

**URL:** https://www.finalbuilder.com/forums/t/how-to-run-a-powershell-script-remotely/1901
**Category:** Discussion
**Created:** [November 23, 2011, 11:06am UTC](https://www.finalbuilder.com/forums/t/how-to-run-a-powershell-script-remotely/1901 "2011-11-23T11:06:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [November 23, 2011, 11:06am UTC](https://www.finalbuilder.com/forums/t/how-to-run-a-powershell-script-remotely/1901/1 "2011-11-23T11:06:56Z")

</div>

Hi,

I have to run a PowerShell-Script on a remote machine from with FinalBuilder 7. I tried the action "Execute PowerShell Script" and copied the following sample code on the tab "Script" under option "Specify Script":

Enter-PSSession %DeploymentServer%  
Get-Content Env:COMPUTERNAME  
Exit-PSSession

I expected that the output in the Build Log tab shows the name of the remote machine, but it shows the name of the local machine running FinalBuilder.

Please note, that the server running FinalBuilder is already registered as a trusted host and if I open the PowerShell command prompt and execute the above 3 lines, the name of the remote machine is shown.

So how can I execute a PowerShell remotely within FinalBuilder?

Kind regards,  
Marcus

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [November 23, 2011, 1:41am UTC](https://www.finalbuilder.com/forums/t/how-to-run-a-powershell-script-remotely/1901/2 "2011-11-23T01:41:25Z")

</div>

Hi Marcus   
  
 We’ll need to do more investigation on this, but from my quick googling it appears Enter-PSSession only works for interactive mode powershell, our powershell hosting is not interactive.   
 You might have better luck using New-PSSession /Invoke-Command /Remove-PSSession

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [November 23, 2011, 5:56am UTC](https://www.finalbuilder.com/forums/t/how-to-run-a-powershell-script-remotely/1901/3 "2011-11-23T05:56:04Z")

</div>

Hi Vincent,

you are right, I´ve overseen that this was the wrong commandlet for my purpose. The following shows the desired result:

> Invoke-Command -computerName %DeploymentServer% -scriptBlock { Get-Content Env:COMPUTERNAME }

Thank you for helping me.

Kind regards,  
Marcus
