How to run a PowerShell-Script remotely?

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

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

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