Script works under Script Console, but not as a Run a Script Step

tiago.lagarto.esteves's Avatar


12 Feb, 2018 02:48 PM


I'm trying to execute the following PowerShell script and executing it directly in the server and in Script Console it works fine but when I call it inside of the process as a "Run a Script" it returns an error:

At C:\Octopus\Work\20180212131518--12\Script.ps1:60 char:22
+     function StopNode
+                      ~
Missing function body in function declaration.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingFunctionBody
The remote script failed with exit code 1


$disableRemoteNode = {
        [string] $machineToRemove,
        [string]  $farmName

function SetUnavailable

function StopNode
        [string] $machineToRemove,
        [string] $farmName           

    $mgr = new-object Microsoft.Web.Administration.ServerManager
    $conf = $mgr.GetApplicationHostConfiguration()
    $section = $conf.GetSection("webFarms")
    $webFarms = $section.GetCollection()

    $webFarm = $webFarms | Where-Object {$_.GetAttributeValue("name") -eq $farmName} | Select-Object -First 1

    $servers = $webFarm.GetCollection()

    $localMachine = $machineToRemove

    $server = $servers | Where-Object { $_["address"] -eq $localMachine}

    Write-Host 'removing machine' $server["address"]

    $arr = $server.GetChildElement("applicationRequestRouting")

    SetUnavailable $arr

Write-Host 'Machine: ' $balancerMachine
Write-Host 'Removing server from farm: ' $machineToRemove
Write-Host 'Farm: ' $farmName
StopNode -machineToRemove $machineToRemove -farmName $farmName

$machineToRemove = 'PC1' $farmName = 'farm' $balancerMachine = 'PC2' $Session = New-PSSession -ComputerName $balancerMachine
Invoke-Command -Session $Session -ScriptBlock $disableRemoteNode -ArgumentList $machineToRemove,$farmName
Any ideas what could be the problem ?


  1. Support Staff 1 Posted by Robert Wagner on 13 Feb, 2018 05:18 AM

    Robert Wagner's Avatar


    Thanks for getting in touch. I've copied the above into a step and it seems to execute fine up until the Administration section without a problem (since I don't have that installed).

    Could you try creating a new project with just this script in it? Then simplifying the script until it works?

    Also could you export that deployment process (available in the UI in v4.0), as well as send me the data from the console task that did work. You can do this by viewing the results of the task and changing the app# in the url to api. You should get the JSON of the task.

    Rob W

  2. 2 Posted by tiago.lagarto.e... on 05 Mar, 2018 08:44 PM

    tiago.lagarto.esteves's Avatar

    Hi Rob,

    Thanks for your help, just to close this topic, the problem was that after fixing the script I did not create a new release, instead, I was re-deploying the old one.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac