Creating IIS AppPool, Unexpected token in expression or statement

Hi. Using the step template for creating an IIS AppPool. This has worked fine for almost a year. Changed the username, and got the errors below. Changed back, but still happens. Tried importing the latest version of the script (from yesterday), same problem. Have tried on two machines, same behaviour.

Any ideas?

TIA, Peter

At C:\Octopus\Work\20160115153247-2114\Script.ps1:2 char:7
16:32:57Error

  • “Id”: “ActionTemplates-99”,
    16:32:57Error
  •   ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:8 char:39
16:32:57Error

  • "Octopus.Action.Script.ScriptBody": "## ---------------------------------
    

16:32:57Error
— …
16:32:57Error

  •                                   ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:14 char:13
16:32:57Error

  •   "Name": "AppPoolName",
    

16:32:57Error

  •         ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:19 char:30
16:32:57Error

  •     "Octopus.ControlType": "SingleLineText"
    

16:32:57Error

  •                          ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:23 char:13
16:32:57Error

  •   "Name": "AppPoolIdentityType",
    

16:32:57Error

  •         ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:28 char:30
16:32:57Error

  •     "Octopus.ControlType": "Select",
    

16:32:57Error

  •                          ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:33 char:13
16:32:57Error

  •   "Name": "AppPoolIdentityUser",
    

16:32:57Error

  •         ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:38 char:30
16:32:57Error

  •     "Octopus.ControlType": "SingleLineText"
    

16:32:57Error

  •                          ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:42 char:13
16:32:57Error

  •   "Name": "AppPoolIdentityPassword",
    

16:32:57Error

  •         ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
At C:\Octopus\Work\20160115153247-2114\Script.ps1:47 char:30
16:32:57Error

  •     "Octopus.ControlType": "Sensitive"
    

16:32:57Error

  •                          ~
    

16:32:57Error
Unexpected token ‘:’ in expression or statement.
16:32:57Error
Not all parse errors were reported. Correct the reported errors and try again.
16:32:57Error
+ CategoryInfo : ParserError: (:slight_smile: [], ParentContainsErrorRecordEx
16:32:57Error
ception
16:32:57Error
+ FullyQualifiedErrorId : UnexpectedToken
16:32:57Error
16:32:57Error
The remote script failed with exit code 1

Hi Peter,

Thanks for reaching out. It seems to be a template parsing error rather than something related to your user.

Could you send over the full exporte JSON of the step template? Please send the one from your Octopus instance and not the one from our library.

Thanks,
Dalmiro

Sure, here it is (latest version, imported today. All parameters show up as they should, so at least the server side can parse it):

{
“Id”: “ActionTemplates-99”,
“Name”: “IIS AppPool - Create”,
“Description”: “Creates or Reconfigures an IIS Application Pool”,
“ActionType”: “Octopus.Script”,
“Version”: 6,
“Properties”: {
“Octopus.Action.Script.ScriptBody”: “## --------------------------------------------------------------------------------------\n## Input\n## --------------------------------------------------------------------------------------\n\n$appPoolName = $OctopusParameters[‘AppPoolName’]\n\n$appPoolIdentityType = $OctopusParameters[‘AppPoolIdentityType’]\nIF ($appPoolIdentityType -eq 3)\n{\n $appPoolIdentityUser = $OctopusParameters[‘AppPoolIdentityUser’]\n $appPoolIdentityPassword = $OctopusParameters[‘AppPoolIdentityPassword’]\n}\n\n$appPoolAutoStart = [boolean]::Parse($OctopusParameters[‘AppPoolAutoStart’])\n$appPoolEnable32BitAppOnWin64 = [boolean]::Parse($OctopusParameters[‘AppPoolEnable32BitAppOnWin64’])\n\n$appPoolManagedRuntimeVersion = $OctopusParameters[‘AppPoolManagedRuntimeVersion’]\n$appPoolManagedPipelineMode = $OctopusParameters[‘AppPoolManagedPipelineMode’]\n\n$appPoolIdleTimeout = [TimeSpan]::FromMinutes($OctopusParameters[‘AppPoolIdleTimeoutMinutes’])\n$appPoolMaxProcesses = [int]$OctopusParameters[‘AppPoolMaxProcesses’]\n$appPoolRegularTimeInterval = [TimeSpan]::FromMinutes($OctopusParameters[‘AppPoolRegularTimeInterval’])\n$appPoolQueueLength = [int]$OctopusParameters[‘AppPoolQueueLength’]\n\n$appPoolStartMode = $OctopusParameters[‘AppPoolStartMode’]\n\n## --------------------------------------------------------------------------------------\n## Helpers\n## --------------------------------------------------------------------------------------\n# Helper for validating input parameters\nfunction Validate-Parameter([string]$foo, [string[]]$validInput, $parameterName) {\n IF (! $parameterName -contains “Password”) \n { \n Write-Host “${parameterName}: $foo” \n }\n if (! $foo) {\n Write-Host “No value was set for $($parameterName), and it cannot be empty”\n }\n}\n\n# Helper to run a block with a retry if things go wrong\n$maxFailures = 5\n$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4\nfunction Execute-WithRetry([ScriptBlock] $command) {\n\t$attemptCount = 0\n\t$operationIncomplete = $true\n\n\twhile ($operationIncomplete -and $attemptCount -lt $maxFailures) {\n\t\t$attemptCount = ($attemptCount + 1)\n\n\t\tif ($attemptCount -ge 2) {\n\t\t\tWrite-Output “Waiting for $sleepBetweenFailures seconds before retrying…”\n\t\t\tStart-Sleep -s $sleepBetweenFailures\n\t\t\tWrite-Output “Retrying…”\n\t\t}\n\n\t\ttry {\n\t\t\t& $command\n\n\t\t\t$operationIncomplete = $false\n\t\t} catch [System.Exception] {\n\t\t\tif ($attemptCount -lt ($maxFailures)) {\n\t\t\t\tWrite-Output (“Attempt $attemptCount of $maxFailures failed: " + $.Exception.Message)\n\t\t\t\n\t\t\t}\n\t\t\telse {\n\t\t\t throw “Failed to execute command”\n\t\t\t}\n\t\t}\n\t}\n}\n\n## --------------------------------------------------------------------------------------\n## Configuration\n## --------------------------------------------------------------------------------------\nValidate-Parameter $appPoolName -parameterName “Application Pool Name”\nValidate-Parameter $appPoolIdentityType -parameterName “Identity Type”\nIF ($appPoolIdentityType -eq 3)\n{\n Validate-Parameter $appPoolIdentityUser -parameterName “Identity UserName”\n Validate-Parameter $appPoolIdentityPassword -parameterName “Identity Password”\n}\nValidate-Parameter $appPoolAutoStart -parameterName “AutoStart”\nValidate-Parameter $appPoolEnable32BitAppOnWin64 -parameterName “Enable 32-Bit Apps on 64-bit Windows”\n\nValidate-Parameter $appPoolManagedRuntimeVersion -parameterName “Managed Runtime Version”\nValidate-Parameter $appPoolManagedPipelineMode -parameterName “Managed Pipeline Mode”\n\nValidate-Parameter $appPoolIdleTimeout -parameterName “Process Idle Timeout”\nValidate-Parameter $appPoolMaxProcesses -parameterName “Maximum Worker Processes”\n\nValidate-Parameter $appPoolStartMode -parameterName “Start Mode”\n\n#Load Web Admin DLL\n[System.Reflection.Assembly]::LoadFrom( “C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll” )\n\nAdd-PSSnapin WebAdministration -ErrorAction SilentlyContinue\nImport-Module WebAdministration -ErrorAction SilentlyContinue\n\n\n## --------------------------------------------------------------------------------------\n## Run\n## --------------------------------------------------------------------------------------\n\n$iis = (New-Object Microsoft.Web.Administration.ServerManager)\n\n$pool = $iis.ApplicationPools | Where {$.Name -eq $appPoolName} | Select-Object -First 1\n\nIF ($pool -eq $null)\n{\n Write-Output “Creating Application Pool ‘$appPoolName’”\n Execute-WithRetry {\n $iis = (New-Object Microsoft.Web.Administration.ServerManager)\n $iis.ApplicationPools.Add($appPoolName)\n $iis.CommitChanges()\n }\n}\nELSE\n{\n Write-Output “Application Pool ‘$appPoolName’ already exists, reconfiguring.”\n}\n\nExecute-WithRetry {\n $iis = (New-Object Microsoft.Web.Administration.ServerManager)\n $pool = $iis.ApplicationPools | Where {$.Name -eq $appPoolName} | Select-Object -First 1\n\n Write-Output “Setting: AutoStart = $appPoolAutoStart”\n $pool.AutoStart = $appPoolAutoStart;\n \n Write-Output “Setting: Enable32BitAppOnWin64 = $appPoolEnable32BitAppOnWin64”\n $pool.Enable32BitAppOnWin64 = $appPoolEnable32BitAppOnWin64;\n \n Write-Output “Setting: IdentityType = $appPoolIdentityType”\n $pool.ProcessModel.IdentityType = $appPoolIdentityType\n \n IF ($appPoolIdentityType -eq 3)\n {\n Write-Output “Setting: UserName = $appPoolIdentityUser”\n $pool.ProcessModel.UserName = $appPoolIdentityUser\n \n Write-Output “Setting: Password = [Omitted For Security]”\n $pool.ProcessModel.Password = $appPoolIdentityPassword\n }\n \n Write-Output “Setting: ManagedRuntimeVersion = $appPoolManagedRuntimeVersion”\n $pool.ManagedRuntimeVersion = $appPoolManagedRuntimeVersion\n \n Write-Output “Setting: ManagedPipelineMode = $appPoolManagedPipelineMode”\n $pool.ManagedPipelineMode = $appPoolManagedPipelineMode\n \n Write-Output “Setting: IdleTimeout = $appPoolIdleTimeout”\n $pool.ProcessModel.IdleTimeout = $appPoolIdleTimeout\n \n Write-Output “Setting: MaxProcesses = $appPoolMaxProcesses”\n $pool.ProcessModel.MaxProcesses = $appPoolMaxProcesses\n \n Write-Output “Setting: RegularTimeInterval = $appPoolRegularTimeInterval”\n $pool.Recycling.PeriodicRestart.Time = $appPoolRegularTimeInterval\n \n Write-Output “Setting: QueueLength = $appPoolQueueLength”\n $pool.QueueLength = $appPoolQueueLength\n \n Write-Output “Setting: StartMode = $appPoolStartMode”\n $pool.StartMode = $appPoolStartMode\n \n $iis.CommitChanges()\n}",
“Octopus.Action.Script.Syntax”: “PowerShell”
},
“SensitiveProperties”: {},
“Parameters”: [
{
“Name”: “AppPoolName”,
“Label”: “Application pool name”,
“HelpText”: “The name of the application pool that the application will run under.”,
“DefaultValue”: null,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
}
},
{
“Name”: “AppPoolIdentityType”,
“Label”: “Identity Type”,
“HelpText”: “The type of identity that the application pool will be using.”,
“DefaultValue”: “3”,
“DisplaySettings”: {
“Octopus.ControlType”: “Select”,
“Octopus.SelectOptions”: “0|Local System\n1|Local Service\n2|Network Service\n3|Specific User…\n4|Application Pool Identity”
}
},
{
“Name”: “AppPoolIdentityUser”,
“Label”: “Specific User Name”,
“HelpText”: "
(Specific User)_ The user name to use with the application pool identity.”,
“DefaultValue”: null,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
}
},
{
“Name”: “AppPoolIdentityPassword”,
“Label”: “Specific User Password”,
“HelpText”: “(Specific User) The password for the specific user to use with the application pool identity.”,
“DefaultValue”: null,
“DisplaySettings”: {
“Octopus.ControlType”: “Sensitive”
}
},
{
“Name”: “AppPoolEnable32BitAppOnWin64”,
“Label”: “Enable 32-Bit Applications”,
“HelpText”: “Allows the application pool to run 32-bit applications when running on 64-bit windows.”,
“DefaultValue”: “True”,
“DisplaySettings”: {
“Octopus.ControlType”: “Checkbox”
}
},
{
“Name”: “AppPoolAutoStart”,
“Label”: “Start Automatically”,
“HelpText”: “Automatically start the application pool when the application pool is created or whenever IIS is started.”,
“DefaultValue”: “True”,
“DisplaySettings”: {
“Octopus.ControlType”: “Checkbox”
}
},
{
“Name”: “AppPoolManagedRuntimeVersion”,
“Label”: “Managed Runtime Version”,
“HelpText”: “Specifies the CLR version to be used by the application pool.”,
“DefaultValue”: “v4.0”,
“DisplaySettings”: {
“Octopus.ControlType”: “Select”,
“Octopus.SelectOptions”: “v1.1|CLR v1.1 (.NET 1.0, 1.1)\nv2.0|CLR v2.0 (.NET 2.0, 3.0, 3.5)\nv4.0|CLR v4.0 (.NET 4.0, 4.5)”
}
},
{
“Name”: “AppPoolManagedPipelineMode”,
“Label”: “Managed Pipeline Mode”,
“HelpText”: “Specifies the request-processing mode that is used to process requests for managed content.”,
“DefaultValue”: “Integrated”,
“DisplaySettings”: {
“Octopus.ControlType”: “Select”,
“Octopus.SelectOptions”: “0|Integrated\n1|Classic”
}
},
{
“Name”: “AppPoolIdleTimeoutMinutes”,
“Label”: “Process Idle Timeout”,
“HelpText”: “Amount of time (in minutes) a worker process will remain idle before it shuts down. A value of 0 means the process does not shut down after an idle timeout.”,
“DefaultValue”: “20”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
}
},
{
“Name”: “AppPoolMaxProcesses”,
“Label”: “Maximum Worker Processes”,
“HelpText”: “Maximum number of worker processes permitted to service requests for the application pool.”,
“DefaultValue”: “1”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
}
},
{
“Name”: “AppPoolRegularTimeInterval”,
“Label”: “Regular Time Interval”,
“HelpText”: “Period of time (in minutes) after which an application pool will recycle. A value of 0 means the application pool does not recycle on a regular interval.”,
“DefaultValue”: “1740”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
}
},
{
“Name”: “AppPoolQueueLength”,
“Label”: “Queue Length”,
“HelpText”: “Maximum number of requests that HTTP.sys will queue for the application pool. When the queue is full, new requests receive a 504 “Service Unavailable” response.”,
“DefaultValue”: “1000”,
“DisplaySettings”: {
“Octopus.ControlType”: “SingleLineText”
}
},
{
“Name”: “AppPoolStartMode”,
“Label”: “Start Mode”,
“HelpText”: “Specifies whether the application pool should run in On Demand Mode or Always Running Mode.”,
“DefaultValue”: “OnDemand”,
“DisplaySettings”: {
“Octopus.ControlType”: “Select”,
“Octopus.SelectOptions”: “OnDemand|On Demand\nAlwaysRunning|Always Running”
}
}
],
“LastModifiedOn”: “2016-01-14T03:17:15.216+00:00”,
“LastModifiedBy”: “ekrapfl”,
”$Meta": {
“ExportedAt”: “2016-01-14T03:17:15.216Z”,
“OctopusVersion”: “3.2.14”,
“Type”: “ActionTemplate”
}
}

Some more info: I think I pressed ‘Update temple’ when entering the new username, although I don’t recall ever updating the template in my library. Could it be an issue when updating from Octopus 2 -> 3? (the process was originally created in v2).

I have another project that references the same step, but that still works. I added a new process step however, using the ‘new’ template, and this failed with the same error message.

No idea what the root problem was, but of course it was fixed when actually importing the template instead of copy/paste. I blame stress…

It would be nice if there was an easier way of updating a template though. I have 11 steps depending on this template, and it takes a while recreating them. (now I’ve had to rename the original, then recreate the steps one by one with the new template, as I’ve found no way to replace the script)

Hi Peter,

Glad to hear its working now. Please let me know if you need further help.

Dalmiro